I have html like this:
<div class="item">
<img class="item-image" src="${item.getImage()}"/>
<p>${item.getName()}</p>
</div>
and Javascript:
var classname = document.getElementsByClassName("item");
for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', (e) => {
addBorder(e.target);
});
};
function addBorder(item) {
if (item.tagName = 'DIV') {
item.style.border = "3px solid red";
}
}
When I click on item, it adds a red border. However if the click happened to touch the image or the paragraph, the red border is drawn around them. I tried to prevent it by adding the if condition inside addBorder
, but it didn't help. Is there a way to only make the parent div red-bordered, even if the click happened to land inside p
or img
?
I have below array how to get list of names where the age is greater than 18. so the out put should be: ["Anna", "Bob"] friends = [{ name: 'Anna', books: ['Bible', 'Harry Potter'], age: 21 }, ...
I have below array how to get list of names where the age is greater than 18. so the out put should be: ["Anna", "Bob"] friends = [{ name: 'Anna', books: ['Bible', 'Harry Potter'], age: 21 }, ...
When I click more button my div 1 is replacing div 2. Most of the time div2 contains lots of text, and requires users to scroll down in order to read the entire post. The problem is that by clicking ...
When I click more button my div 1 is replacing div 2. Most of the time div2 contains lots of text, and requires users to scroll down in order to read the entire post. The problem is that by clicking ...
I have some squares sliding down the page, in a chained promise fashion: https://jsfiddle.net/u4x0qwfo/3 The code is: new Promise(function(resolve, reject) { $("#shape").css({ top: 100 }); ...
I have some squares sliding down the page, in a chained promise fashion: https://jsfiddle.net/u4x0qwfo/3 The code is: new Promise(function(resolve, reject) { $("#shape").css({ top: 100 }); ...
I have many dinamic tables, each one creates a dinamic master checkbox inside an input and several checkboxes inside td's (each one has a different ID). The idea is once I check or uncheck the master ...
I have many dinamic tables, each one creates a dinamic master checkbox inside an input and several checkboxes inside td's (each one has a different ID). The idea is once I check or uncheck the master ...