简体   繁体   English

当我们只有孩子的ID时,如何使用js更改父div的宽度和高度

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

How can I change the width and height of parent div using js when we only have the id of the child 当我们只有孩子的ID时,如何使用js更改父div的宽度和高度

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

The div comes from the Database. div来自数据库。 so i cannot modify that 所以我不能修改

使用parentElement

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用 javascript 滚动事件更改 div 的宽度和高度吗? - Can I change the width and height of a div using javascript scroll event? 如何根据子div的高度更改父div的高度? - How would I change the height of a parent div based on the height of a child div? 如何创建一个单击事件,其中我有多个 div,并且每个 div 都有一个具有相同 Id 的按钮,但单击时仅影响父 div,如何? - How can I create a click event where I have several div's and each having a button with the same Id but when clicked only affect the parent div, how? 触发父级div大小时如何调整子div大小 - How can we resize child div when we trigger parent resize div 使用CSS Trasition时如何更改父div的高度? - How to change height of parent div when using css trasition? 根据孩子的身高/宽度填写父div - Fill parent div based on child height/width 我有DIV及其子DIV,我想使用jQuery选择最后一个DIV。 父级DIVS有ID - I have DIV and its child DIV , i want to select last DIV using jQuery . Parent DIVS have id jQuery的父div的子元素的宽度和高度相同 - Jquery have a parent div have the same width and height of it's child element 如何将子 div 宽度设置为等于 max-width 但以父级为中心 - How can I set child div width equal to to max-width but centered of parent 我想使用 angular 根据 window 调整大小动态更改父子 div 的高度 - I want to dynamically change the parent and child div's height based on the window resize using angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM