I am having two div tags . i like to add class on click event for current div .
But after that, when i click second div , both the div has the class.
how to remove class for previous div?
<div title="a1"></div>
<div title="a1"></div>
$('[title:a1]').click(function() {
$(this).addClass('current');
});
where should i wright remove class ?
You need
=in your attribute-equals selector:Note, you should use something like
div[title=a1]instead here…anything to narrow that expensive selector down.To remove the
currentclass from the previously selected one, just do this: