Friday 15 February 2013

Jquery add class not working? -



Jquery add class not working? -

here jquery:

$('.portfoliopod').on('click', function(){ $('.portfoliopod').addclass('current'); });

and html:

<div class="portfoliopod"> <img class="portfolioimage" src="aboutme.jpg"> <div class="portfoliopodmessage">testing 123</div> </div>

when click "portfolio pod" section class "current" not added. missing obvious here?

as op said "on click of button portoflio loaded through php", assume portfolio content loaded via ajax. so, have utilize hear event on element :

jquery(document).on('click', '.portfoliopod', function(){ jquery('.portfoliopod').addclass('current'); });

as .portfoliopod element dynamically created element, code you're using won't bind event element going come in dom tree later.

so, way of binding listener bind on document , check if element clicked on document .portfoliopod. see this.

also, seems on site, $ undefined (very strange). so, utilize jquery instead.

or, if want $ object, add together code @ end of jquery file before })(window); :

window.jquery = window.$ = jquery;

jquery

No comments:

Post a Comment