Tarsem Singh
Tarsem Singh

Reputation: 21

document.ready() function not working

I am working for selecting the text from a text box to the clipboard with the help of zclip. But the document.ready() is not working. It is not even showing the alert. All required libraries are above the script tag and inside the head section. All the files are at the required positions.

I have even checked the files along with the full URL.

<script type="text/javascript" language="javascript">
$(document).ready(function(){
alert('hi');
        $("a#copy_initiator").zclip({
            alert('hi');
            path:"js/ZeroClipboard.swf",
           copy:function(){return $("input#copy-box").val();}
        });
    });
</script>


<a id="copy_initiator">Copy Link:</a> <input id="copy-box" type="text"  value="here_is_a_url" onfocus="this.select();">

Upvotes: 2

Views: 17935

Answers (2)

montueron
montueron

Reputation: 198

you say "All required libraries", are you including several libraries ?

If this is the case, it could be possible that they are creating a conflict with jquery "$".

here is a webpage explaining this : https://api.jquery.com/jQuery.noConflict/

a test you can do, is going to your console entry in your browser's debugguer and try typing $('div'), or $('p'). If any of the html tags you select are recognize it means the $ is working, otherwise not.

Upvotes: 0

Bilal
Bilal

Reputation: 429

you have a syntax problem here:

    $("a#copy_initiator").zclip({
        alert('hi');
        path:"js/ZeroClipboard.swf",
       copy:function(){return $("input#copy-box").val();}
    });

should be:

$("a#copy_initiator").zclip({
    path:"js/ZeroClipboard.swf",
    copy:function(){
        return $("input#copy-box").val();
    }
});

And better version:

$("#copy_initiator").zclip({
    path:"js/ZeroClipboard.swf",
    copy:function(){
        return $("#copy-box").val();
    }
});

Suggestion: use firebug to track these kind of issues.

Upvotes: 2

Related Questions