sairfan1 Posted February 18, 2010 Share Posted February 18, 2010 hi, im try to set a string type attribute of an element like thisMenuItem.setAttribute('onmouseover','this.className=myclass')but in result it removes quote signs and result is onmouseover=this.classNamei also tried 'this.className=myclass' and '"this.className=myclass"' and '"this.className=myclass"'but failedi want out put like this onmouseover='this.className=abc'please help thanks Link to comment Share on other sites More sharing options...
jeffman Posted February 18, 2010 Share Posted February 18, 2010 We do not add event listeners with setAttribute. This page at Mozilla explains the correct DOM techniques, which must be adapted to be cross-browser. The traditional technique is also shown. The traditional way remains my preference because it is simple and always works. Here is more discussion of that. Link to comment Share on other sites More sharing options...
sairfan1 Posted February 20, 2010 Author Share Posted February 20, 2010 Hi thx for reply.im receiving object does not support this property/method error while using .addEventListenermore over this code soved the problem .setAttribute('onclick','this.className="ABC"') We do not add event listeners with setAttribute. This page at Mozilla explains the correct DOM techniques, which must be adapted to be cross-browser. The traditional technique is also shown. The traditional way remains my preference because it is simple and always works. Here is more discussion of that. Link to comment Share on other sites More sharing options...
boen_robot Posted February 20, 2010 Share Posted February 20, 2010 Hi thx for reply.im receiving object does not support this property/method error while using .addEventListenermore over this code soved the problem .setAttribute('onclick','this.className="ABC"')(Re?)read the Internet Explorer part of the article above. If the drawback is troublesome for you, use the older way to register event listeners. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.