質問

I have Simple Table with some TDs having Class as 'PLUS' and Some TDs with class 'MINUS'.

I am implementing the Collapse all and Expand All functionality using jquery.

On click of Expand All, I want to replace 'PLUS' class with 'MINUS' of only TDs who has 'PLUS' class.

and on click of Collapse All, replace 'MINUS' class with 'PLUS'

I am facing problem for finding all TDs with plus class and iterate through all of them to replace class

Any Suggestions please?

役に立ちましたか?

解決

There is no need to iterate, jQuery will do this for you very conveniently.

It's not very clear from the question what exactly you want to do, but you can:

  • Switch .plus to .minus with

    $(".plus").toggleClass("plus minus")
    
  • Toggle .plus and .minus on all elements that have either with

    $(".plus, .minus").toggleClass("plus minus")
    

他のヒント

A selector for an element with a class is {tag}.{class} http://css.maxdesign.com.au/selectutorial/selectors_class.htm

// When clicked, replace all td.plus with td.minus
$('td.plus').click(function(){
    $('td.plus').toggleClass('plus minus')
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top