i am using a javascript function to replace a class applied to an element but its not working. code is as follows
function replace_class(kwe){
var aq=document.getElementById('#il' + kwe);
var rem=" xm14";
aq.className=aq.className.replace(rem,"");
}
the above function is called when user clicks on the div. "KWE" is the numerical value which will be needed later to pinpoint that particular element. the class which i want to remove is named as "xm14".
but nothing happening if i clicks on the element.
here is the html div code
<div class="tryPond xm14" id="il1" onClick="replace_class(1);"><?php echo $getCatList[0]->getCatName();?></div>
Your element selector is wrong. Simple solution:
var aq = document.getElementById("il" + kwe); // no "#" needed
Try that. Also consider using jQuery, it may make your life easier in the long run.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.