简体   繁体   中英

Changing the position of a dynamically added element

I am trying to change the position and style of a dynamically added element, but my changes are not taking affect. Any ideas why?

I appreciate your assistance.

function addButtons()
{
  var button1 = document.createElement('button');

  button1.innerHTML = 'Relevant';

  button1.onclick = function()
  {
    alert('test');
    return false;
  };


  document.getElementsByClassName('subject')[0].appendChild(button1).style.left="6000px";


};

如果元素不具有position: absoluteposition: fixedposition: relative ,则作为内联样式或从样式表继承, left均无效

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM