English 中文(简体)
j 质量:CSS的等值。
原标题:jQuery: equivalent of .live() for CSS?

我如何在积极创造的要素中增加安保部?

下面是我要做的简单例子:

$(document).ready(function() { 
    $( #container ).html( <p id="hello">hello world</p> );
    // The following line doesn t work. 
    $( #hello ).css("background-color", "#FFF");
});

我想这样做的原因是,我想到这样做的另一个方式是,我想在动态生成的一张桌子上使用背景颜色:

$("#results-table tr:even").css("background-color", "#FFF");

我需要特别为IE8和以下使用这一分类,而后者不支持nth-child。 CSS 甄选员。

最佳回答

实际上,你的法典确实行之有效。 如果你没有该身份证的多个要素,你可能会想检查。

Edit: Here s your code, without duplicate IDs: http://jsfiddle.net/FhTU7/

Final edit: Your HTML background and element background are both white.

问题回答

你可以不直接设立特别安全局,而只是把一个班子加到哪里。

$("#results-table tr:even").addClass("alt");

CSS: 为候补行设计彩色,然后为不同颜色

<style type="text/css">
tr
{
    background: #fff;
    color: #000;
}

tr.alt
{
    background: #000;
    color: #fff;
}
</style>

你可以宣布新内容为变数......

$(document).ready(function() { 
    var $new = $( <p id="hello">hello world</p> );
    $new.css({
        backgroundColor: "#fff"
    })
    $( #container ).append($new);
});

页: 1

$(document).ready(function() { 
    $( <p id="hello">hello world</p> ).appendTo( #container ).css({
        backgroundColor: "#fff"
    })
});

然而,如果你正确地制造这些要素,你就可以最终使用原来的特别安全局。

    $( #container ).append( <p id="hello">hello world</p> );        




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签