Select the son of the relative of a selected div

1

I am trying to make a pop-up tab of a div table and would like to change the value of a div, specifically the son of a father who knows his id, something like this:

<div id="pariente">
  <div id="hijo">Inactivo</div>
</div>
<div id="selector-1">Selector</div>

function toggle_visibility(id) { 
        var e = document.getElementById(id); 
        e.style.display = ((e.style.display!='none') ? 'none' : 'block'); 
}

An additional fact is that the id = Relative is a module of several repeats, and there is more selector-1. I need to click on the selector in another div to access the div = Son and change the "Inactive" to "Active". Thank you very much, I look forward to your answers. Greetings

    
asked by Armando García 29.11.2016 в 05:40
source

2 answers

2

You should not have several id=pariente but if you can not differentiate that div from others you can select the previous item and then your child, something like this:

window.onload = function() {
  document.getElementById("selector-1").addEventListener("click", function() {
    this.previousElementSibling.firstElementChild.innerHTML = "activo";
  });
};
#selector-1 {
  cursor: pointer;
}
#selector-1:hover {
  color: red;
}
<div id="pariente">
  <div id="hijo">inactivo</div>
</div>
<div id="selector-1">selector</div>
    
answered by 29.11.2016 в 08:49
0

It could be document.querySelector("pariente").children[0].innerHTML = "Inactivo"#

Obviously with the programming of the interchangeable value to be able to put Active and Inactive

    
answered by 29.11.2016 в 06:34