开发者

Working with Jquery. How to change css class of an element in same root

I want to change css class of an element on certain event in jquery. eg.

            focusin: function()
                {
                    if(this.val()=="First Name")
                        $(this).find("span ").css
                }

$(this).find("span which contains _set").class= mycssclass here I want to change the CSS class of span element whose id contains "_set" as a part of substring in class name and also want to change the tex开发者_StackOverflowt i.e. InnerHtml property of javascript of this span element


something like this

$("span[id*='_set']").toggleClass("newcssclass").text("new text").

regards


where does it contains "_set" in the ID ,CLASS or in the innterHTML ?

to look for some string in the innerHTML you need to use something like this:

$("span:contains('_set')").toggleClass("yourcustomclass").html("blabla")

if the "_set" is in the ID or in the class use it like "hworangdo" told you. In your case:

$("span[id*='_set']").toggleClass("yourcustomclass").text("new text").

why are you using "$(this)" before the ".find()" in your example?


.removeClass() + .addClass() should do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜