javascript - jQuery onClick for an Already Modified Class -


i have lets user click <li> toggles div below it. inside div button "add short list". when clicked, changes background of li item, changes button text "remove short list". when button pressed again, needs opposite of adding, must change li class it's original state , change button text back.

i having trouble getting work. know once change class name i'm unable access new class via onclick.

in addition, when button clicked, if it's "adding" ajax occurring (implemented later on) , when it's clicked "remove" ajax occur remove corresponding thing.

javascript

var incsl  $('.complete, .incomplete').click(function() {      $('.classinfo').slideup();      if($(this).next().is(':hidden') == true) {          $(this).addclass('on');          $(this).next().show('slow');          incsl = this;          // add         $(".shortadd").on('click','.button', function(){              $(this).text('remove short list');              $(this).parent().attr("class", "shortremove");              $(incsl).attr("class", "incompletesl");          });          // remove         $(".shortremove .button").click(function(){              $(this).text('add short list');              $(this).parent().attr("class", "shortadd");              $(incsl).attr("class", "incomplete");          });      }    }); 

html

<li class="incomplete">itcs 3688 computers & society</li>     <div class="classinfo">         <div class="shortadd">             <div class="button">add short list</div>         </div>     </div> 

css

.incomplete {     filter: alpha(opacity=65);     -moz-opacity: 0.65;     -khtml-opacity: 0.65;     opacity: 0.65; }  .incompletesl {/* short listed */     background: url('../images/short.png') right center no-repeat;     color: #00703c;     opacity: 1.0; } 

thanks 1 can provide! :d

try this:

$('body').on('click', 'element_class_or_id', function () {}); 

you can find live events in jquery documentation. :)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -