You have written:
$('a').bind('click', function(){
idName = "#" + $(this).attr('id');
className= $(this).attr('id');
var getClassElem = $(this).attr('class');
alert(getClassElem);
$("a").removeClass();
$(idName).addClass(className);
});
It can be optimized as:
$('a').click(function(){
$("a").removeAttr("class");
$(this).addClass($(this).attr("id"));
});
Few other things:
- What are you trying to do?
- How can you have a
<div>
element inside an<a>
element?