使css表适用于javascript中的“后页加载”html元素

时间:2022-12-15 13:21:27

I have a div in my page which I create with javscript when the mouse is over a specific area of the page(like a tool tip). The thing is that my css sheet has no effect over this div I create, to which I also set its id. is there a way to make my css sheet apply over that div? Thanks.. Code:

我的页面中有一个div,当鼠标位于页面的特定区域(如工具提示)时,我使用javscript创建。问题是我的css表对我创建的div没有影响,我也设置了它的id。有没有办法让我的CSS表适用于该div?谢谢..代码:

// mouseover event calls:
function showMyToolTip(mouseXPosition, mouseYposition){ 
  // if mosue over object loacated at objLocationX, objLocationY
  if (mouseXPosition == objLocationX&& mouseYPosition == objLocationY){
     var div = document.createElement("div");
     div.setAttribute("id", "divMouseOverObj"); 
     document.appendChild(div);
  }
}

css sheet: div#divMouseOverObj{ width: 100px; color: green; }

css sheet:div #divMouseOverObj {width:100px;颜色:绿色; }

1 个解决方案

#1


Question asked by GolezTrol solved the issue for me.Thanks change in css sheet: divMouseOverObj{ width: 100px; color: green; }

GolezTrol提出的问题为我解决了这个问题。感谢css表中的更改:divMouseOverObj {width:100px;颜色:绿色; }

#1


Question asked by GolezTrol solved the issue for me.Thanks change in css sheet: divMouseOverObj{ width: 100px; color: green; }

GolezTrol提出的问题为我解决了这个问题。感谢css表中的更改:divMouseOverObj {width:100px;颜色:绿色; }