0

i have following button:

<button type="button" class="start-upload-btn">Start Uploading</button>

I'm adding a click listener to it within the script tags:

<script>
    $(document).ready(function() {
    alert(jQuery);
    $('.start-upload-btn').on('click', function() {
        alert(jQuery);
        var myData = ${dataForUpload};
        if (myData) {
            $.each($.parseJSON(myData), function(key,value){
                alert(value.oldFile);
            });
        }
        else {
            alert('No Data');
        }
    });
});
</script>

The alert(JQuery); within the click function does not work on clicking. I can't figure out what's the matter with my code.

Update: i'm using this cdn for JQuery in head.

<script src="https://code.jquery.com/jquery.min.js"></script>

I've updated my code with ready function, but it still isn't working.

3
  • 3
    You need to put your jQuery code inside a DOMReady handler: $(function() { /* your code here */ }); Commented Jan 15, 2015 at 10:54
  • It working fine check jsfiddle.net/26zuxks9 Commented Jan 15, 2015 at 11:18
  • yeah but not in my files Commented Jan 15, 2015 at 11:27

1 Answer 1

1

Write your code in

$(document).ready(function(){----}

and instead of using alert(jQuery) use debugger;

Sign up to request clarification or add additional context in comments.

Comments

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.