I have html element with id:
<img id = "ShowOrHideImage" src="~/Images/show_expander.png"/>
when I place script to to html, I can get message after click:
<script>
$("#ShowOrHideImage").click(function () {
alert("function invoked");
});
</script>
But when I put script to external file MyScript.js:
alert("Script is there");
$("#ShowOrHideImage").click(function () {
alert("function invoked");
});
I get message “Script is there” but never “function invoked”
I don’t know what is the reason. Any ideas? Thank You in advance.
You
externaljavascript file would be loading before the element ofDOMbecome available usingdocument.ready. Also make sure thejQueryfile is inlcluded before external javascript file.