Am trying to sortout this small issue from past hour :
<script type="text/javascript">
$(document).ready(function(){
$("input[name='isClubMember']:checkbox").mousedown(function() {
if (!$(this).is(':checked')) {
this.checked = confirm("Are you sure?");
$(this).trigger("change");
}
});
});
</script>
Funnily this works in JSFiddle ..but not in my jsp page.
Sample
The above code gives me null error at this line (in Debug console)
$("input[name='isClubMember']:checkbox").mousedown(function() {
JQ -Ver : 1.7.2 Browser : IE8
Update :
Error in IE console :
'null' is null or not an object
at the above mentioned line
It looks like your JSP page includes the Prototype library after jQuery.
Prototype’s $() function takes an id and returns
nullif it cannot find the element, which is consistent with the behavior you’re observing.Try using
jQueryinstead of$everywhere in your code:Or put your code in a closure that is passed the
jQueryobject in a$argument:Or take advantage of the fact that a
readyhandler is passed the same$argument:You may also want to run jQuery in noConflict mode, to avoid overriding Prototype’s
$()function if the order of inclusion changes.