开发者

multilple hasclass combos

I'm having a bit of trouble getting around find and selecting multiple classes on div tags.

<div class='class1 class2 class3'></div>

This may have class1 ir class2 etc how would I select class1 ans class2 or class1 orclass3.

Im also having problems fiding $this or each element to display on show or hide.

Thanks


Sorry all, logged on to laptop now, right so ive tried $('div.class1,.class2.class3') etc and all permitations this and it doesnt work for me im afraid.

eg

<div class="benefits risk"&g开发者_StackOverflow社区t;
<div class"risk">
<div class="benefits">

I want to be able to:

$(.here).click(function(){
  if(  $('div')hasClass('benefits')) {
$(this).find('someotherdiv').show();

})

but on the hasclass be able to have AND/OR and unique hasclasses, is this possible?


If you mean finding element that has mor than 1 class you could use:

$(".class1.class2") // this will give you elements that have the 2 classes
$(".class1,.class2") // this will give you elements that have class1 or class2

if you mean check if it's has a class use

$("#mydiv").hasClass("class1") // this will return true or false

note :

  • don't forget the " " inside the $() function

  • no need for the || cause the , do the or logical operator


commas are like OR

$('.class1, .class2, .class3')

concatenation like AND

$('.class1.class2.class3')

just like in CSS


If you'd like to select elements that have class1 and class2 and class3, you select

$(".class1.class2.class3")

If you'd like to select elements that have class1 or class2 or class3, you select

$(".class1, .class2, .class3")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜