weixin_33720078 2012-04-13 02:58 采纳率: 0%
浏览 38

在ajax中用jQuery更新css?

I'm trying to update the css (the css is located in my main.css) of divs that do not exist on my main html file but do in the files i am injecting. Is this possible? if so how?

ok so here is what I have in my main html file

<div id="container">
<div id="page">
    <!placeholder>
</div></div>

sorry about the bad formatting i just can't get the tabs and new lines to work with the code input system on this site.

next is what I have for main.css

#container {
position: fixed;
margin-right: 0px;
overflow-x: hidden;
overflow-y: scroll;}
#page {
position: absolute;
width: 100%;
height: 1600px;
z-index: 10;
border-left: 1px solid #CCCCCC;}
#recposts {
position: absolute;
left:0;
top:1200px;}
.child {
height: 400px;
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
z-index: 11;
background-color: #EDEDED;
width: 100%;
padding-right: 10px;}

alright and now what I'm injecting

<div id ="page">    
<div id="recposts" class="child">
    <h1> Recent Posts  </h1> 
</div></div>

So I need to be able to edit the position top of #recposts and the height of .child.

I fixed my issue the problem was that I wasn't editing the css on the html load. I put the function into the .load() and now it works.

  • 写回答

3条回答 默认 最新

  • weixin_33725270 2012-04-13 03:08
    关注

    If the CSS rules are in a file that is already loaded (your main.css), then any new elements that are added later (say, from whatever HTML you're talking about injecting), and that match selectors in the CSS file, will automatically have the styling rules applied. Is that what you're after?

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误