Append a style on click, then append another style on 2nd click

Here is my code:

http://jsfiddle.net/adige72/BbSd7/

When i click to, suppose "show div 1", it removes dotted border-bottom of it but once it clicked again the border does not return whereas what i want it does.

Answers


Use toggleClass that should do the trick. You're doing an each() which may not be needed. Just hook onto the element that needs to be clicked. Don't need to loop through each parent li etc.

See the first example here: http://api.jquery.com/toggleClass/


I'd suggest you use classes to manage it as it is much cleaner:

$('#element').click(function() {
  if ($(this).hasClass('class1')) {
    $(this).addClass('class2');
  }
}

With styles it is similar. An example:

$('#element').click(function() {
  if ($(this).css('background-color')=='red') {
    $(this).css('color', 'white');
  }
}

Need Your Help

How to get debug information from a c++ application which is shipped to customer?

c++ visual-studio debugging

I am not sure if it is possible but assume that I have a c++ application and I am sendimng to our customers. The application may have bugs and hence it fails, but I can not get any information abou...

how to protect client side codes

php javascript html

is there any open source tool to encrypt or hide the client side code.... is it possible....??? i need to encrypt php,html,java script//