Navigate with a for the child elements of a parent node but that the function is added specifically to the child clicked

0
var ViewDelett0element = function(){
for (var p = 0; p <= List.children.length -1; p++) {
List.children[p].addEventListener("click", function(){List.parentNode.setAttribute("class", "ViewDelett0element")});}
};

Please help me: I am currently trying to add the function (ViewDelett0element) to a specific element that clicks, for now the function is traversed to all the child elements with the for adding the function that the class read to the parent element, but I can not find a way to add it only to the child who clicks specifically and to try everything acontinuation the codes try that failed and are not correct or do not work as I thought.

var ViewDelett0element = function(){
for (var p = 0; p <= List.children.length -1; p++) {
List.children[p].addEventListener("click", function(){List.child(Nodes[p]).setAttribute("class", "ViewDelett0element")});}
};
    
asked by Emmanuel Ruiz 13.07.2016 в 04:25
source

1 answer

1

I do not understand you very well, I hope it helps you

In case it does not help you, let me have a better explanation.

var List = document.querySelector('#list');

var ViewDelett0element = function() {
    for (var p = 0; p <= List.children.length - 1; p++) {
        List.children[p].addEventListener("click", function() {
            this.setAttribute("class", "ViewDelett0element")
        });
    }
};

ViewDelett0element();
ul{
list-style:none;
margin:0;
padding:0;
}

li{
  padding:.5em;
  margin:.3em;
  background:#f1f1f1;
  display:nlock;
}

.ViewDelett0element{
  background:#f00;
  color:#fff;
}
<ul id="list">
<li><span>1</span></li>
<li><span>2</span></li>
<li><span>3</span></li>
<li><span>4</span></li>
<li><span>5</span></li>

</ul>
    
answered by 13.07.2016 / 04:38
source