jquery if div not id
I want to cut the price off to all input value in all divs, except only one div sale_wrap
. how do I make an exception with jquery?
<div id="one_wrap">
<input type="checkbox" name="1" value="">
<input type="checkbox" name="1" value="">
</div>
<di开发者_开发知识库v id="two_wrap">
<input type="checkbox" name="2" value="">
<input type="checkbox" name="2" value="">
</div>
<div id="sale_wrap">
<input type="checkbox" name="3" value="">
</div>
jquery:
if($("div").attr("id") != "sale_wrap") {
t_balance;
} else {
var sale = t_balance*((100-window.discount_p)/100);
t_balance = sale;
}
Use not selector
$("div:not(#sale_wrap)")
The jQuery not()
function can do this.
To select all div's except the div with id
of sale_wrap
:
$('div').not('#sale_wrap')
You can then loop over the divs with each()
.
As an example:
#HTML
<p id="1">Some text in paragraph 1</p>
<p id="2">Some text in paragraph 2</p>
<p id="3">Some text in paragraph 3</p>
#JS
# turn background to blue for all 'p' except p with id=2
$('p').not('#2').each(function() {
$(this).css('background-color', 'blue');
});
Check out this example on JsFiddle.
Try using
if($('div').not('#sale_wrap'))
{
t_balance;
}
else
{
var sale = t_balance*((100-window.discount_p)/100);
t_balance = sale;
}
Just to add little more information. One can use multiple not selector like this:
$("div:not(#sale_wrap):not(.sale_class)");
or
$("div:not(#sale_wrap, .sale_class)");
or
$("div").not('#sale_wrap, .sale_class');
Alternatively:
$('div[id != "sale_wrap"]')
精彩评论