admin管理员组文章数量:1431994
i am making a tree with the help of js and jquery in asp mvc.
there is a add button which add the sibling and same level child .
to identify what is to be done i am using the following code.
//to check from where the function is called
var checkClass = $('#UlPrnt').find('span').css('background-color', 'Lime').length;
if (checkClass == 0) {
AddSiblings();
$('#hdnChkSibbling').val('2');
}
else {
debugger
var getValue = $('#dvTree').find('span').css('background-color', 'Lime');
var spnID = getValue[1].id;
var check = spnID.indexOf("spn");
if (check>0) {
AddSiblings();
$('#'+spnID).css('background-color', '');
}
else {
//call the function to append the same level child
}
}
when i was going through the find function in jquery what i interpreted is that it will return the no of dom where the corresponding bg color is lime.
but what it does it applys the bgcolor to all the span .
how to get the ids of the span whose bgcolor is lime.
every thing is created dynamically (span ,div) just wanted to add for getting a better picture.
i am making a tree with the help of js and jquery in asp mvc.
there is a add button which add the sibling and same level child .
to identify what is to be done i am using the following code.
//to check from where the function is called
var checkClass = $('#UlPrnt').find('span').css('background-color', 'Lime').length;
if (checkClass == 0) {
AddSiblings();
$('#hdnChkSibbling').val('2');
}
else {
debugger
var getValue = $('#dvTree').find('span').css('background-color', 'Lime');
var spnID = getValue[1].id;
var check = spnID.indexOf("spn");
if (check>0) {
AddSiblings();
$('#'+spnID).css('background-color', '');
}
else {
//call the function to append the same level child
}
}
when i was going through the find function in jquery what i interpreted is that it will return the no of dom where the corresponding bg color is lime.
but what it does it applys the bgcolor to all the span .
how to get the ids of the span whose bgcolor is lime.
every thing is created dynamically (span ,div) just wanted to add for getting a better picture.
Share Improve this question edited Dec 1, 2010 at 5:48 RPM1984 73.2k62 gold badges240 silver badges363 bronze badges asked Dec 1, 2010 at 5:47 ankurankur 4,74315 gold badges67 silver badges104 bronze badges3 Answers
Reset to default 6You're using the jQuery .css() method incorrectly. You use .css() to get or to set a css property. For more details see: http://api.jquery./css/.
Instead of using css, you should add a class to all elements that you want to be lime-colored:
$('???').addClass('lime-colored');
Then, in your css file, specify the styling for the lime-colored class:
.lime-colored { background-color:lime; }
Then, when you want to grab all of the elements that are currently green, do so by grabbing the elements that have the lime-colored class appended:
var checkClass = $('#UlPrnt').find('span.lime-colored').length;
If you want to remove lime coloring, you can use the following:
$('???').removeClass('lime-colored');
You have to loop through each then find the attribute lime. Here is an example: jQuery: Can you select by CSS rule, not class?
Another approach though would be to add a class (like background-lime) when you change the background to lime. Then just search for that class, $.(".background-lime").
var ids = $('#UlPrnt span')
//a set of spans with background-color of lime
.filter(function(){
return $(this).css('background-color')=='lime';
})
//a set of ids
.map(function(){ return this.id; });
本文标签: javascriptfind in jquery applying css to all spanStack Overflow
版权声明:本文标题:javascript - find in jquery applying css to all span - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745565032a2663707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论