最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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";

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论