admin管理员组

文章数量:1389762

How can I change the width and height of parent div using js when we only have the id of the child

<li>
  <span id="head-ing"><?=$row['subject']?></span>
  <script>
    /*what js to use*/
  </script>
</li>

The div es from the Database. so i cannot modify that

How can I change the width and height of parent div using js when we only have the id of the child

<li>
  <span id="head-ing"><?=$row['subject']?></span>
  <script>
    /*what js to use*/
  </script>
</li>

The div es from the Database. so i cannot modify that

Share Improve this question edited Apr 14, 2016 at 7:16 Pugazh 9,5615 gold badges36 silver badges56 bronze badges asked Apr 14, 2016 at 7:05 xYLOxxYLOx 311 silver badge2 bronze badges 4
  • I cannot use Inspect Element For that because the there is no ID of the div. – xYLOx Commented Apr 14, 2016 at 7:10
  • you want to change the <li> element ? – Asad Commented Apr 14, 2016 at 7:23
  • No just the parent div element – xYLOx Commented Apr 14, 2016 at 12:14
  • i know it in jquery u can easily access parent by $("#child").parent().css({'height':'200px'}) – Asad Commented Apr 14, 2016 at 12:22
Add a ment  | 

2 Answers 2

Reset to default 4

Use parentElement:

document.getElementById("myLI").parentElement.style.width = "200px";
var child = document.getElementById("childId");
parent = child.parentNode;
parent.style.width= "100px";
parent.style.height= "100px";

本文标签: