javascript - Onclick function not being called -
i have following code http://jsfiddle.net/6xcn6gzj/, need remove element off page using attribute, opted jquery's remove. problem once click on image, nothing happens. tried calling function javascript , working perfectly. reason, event not happening.
html:
<div> <img src="whatever" alt="test" onclick="close('test')"> </div> javascript:
console.log('hi'); function close(template) { console.log(template); $('body').find('img[alt="'+template+'"]').remove(); } the console logging "hi" indicates javascript running fine never logs template name. appreciated.
two problems:
- don't name function
close, conflictwindow.close - your fiddle set load code in onload handler, function local function. change fiddle load script in
<head>http://jsfiddle.net/6xcn6gzj/7/
function doclose(template) { console.log(template); $('body').find('img[alt="' + template + '"]').remove(); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <img src="whatever" alt="test" onclick="doclose('test')" /> </div>
Comments
Post a Comment