Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

javascript - Remove onclick event from img tag

Heres my code:

<div id="cmdt_1_1d" class="dt_state1" onclick="sel_test(this.id)">
<img id="cmdt_1_1i" onclick="dropit('cmdt_1_1');" src="/site/hitechpackaging/images/items/bags_menu.jpg ">
<span class="dt_link">
<a href="javascript://">BAGS</a>
</span>
</div>

Unfortunately I cannot modify this file, is there a way using javascript to disable the onclick from the img tag only.

I was using this script but it disable the onclick event from all images. But i want only from this component

var anchorElements = document.getElementsByTagName('img');
// for (var i in anchorElements)
 //   anchorElements[i].onclick = function() {
       // alert(this.id);
 //       return false;
 //   }

Any ideas will be appreciated.

Edited: Is there a way to stop the function dropit from executing, is it possible using javascript. On page load, etc.

another option is can i rename the img file using javascript??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
document.getElementById('cmdt_1_1i').removeAttribute("onclick");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...