Wednesday, 18 September 2013

JQuery addclass to selected div, remove class if another div is selected

JQuery addclass to selected div, remove class if another div is selected

I'm making a formbuilder, I would like to change the appearance of for
example a heading div. When clicked it should get a border but when
another dynamically generated div is clicked the class should be removed
and the second clicked div has to get the .active class.
How can I do this with generated divs?
Code:
/* Add Class Heading*/
$(document).ready(function() {
$(this.attr('id')).click(function () {
var DivId = $(this).attr('id');
alert(DivId);
$(this).addClass('active');
});
});

No comments:

Post a Comment