0

I'd like to have some jquery in my html on my custom wordpress page. Now this does work (from an example):

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
    alert("Action ABC")
});
});
</script>

Whereas this does not. There simply doesn't happen anything when the box is checked.

<p id="agre"> <input type="checkbox" name="agre">

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(function(){
     $('#agre').click(function(){
            var agree_conf = confirm("Action A");
            if (agree_conf == true) {
                window.location = "http://www.google.com"
            }
         })
</script>

This has maybe to do with the proper jquery/wordpress call. But I can't figure it out.

1
  • The p-tag doesn't have closing tag, that breaks the dom, try adding the </p> Commented Apr 11, 2014 at 9:43

1 Answer 1

3

Try to add }); to close your DOM ready handlder:

$(function () {
    $('#agre').click(function () {
        var agree_conf = confirm("Action A");
        if (agree_conf == true) {
            window.location = "http://www.google.com"
        }
    })
}); // <-- Here
Sign up to request clarification or add additional context in comments.

1 Comment

That wasn't it. But your comment made me find my error: wordpress seems to put <p> tags wherever I insert a break in my script. Didn't know that. Adjusted it and changed the function to $(document).ready(function(){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.