1

I got this script:

<script>
    $(document).ready(function () {
        $('a[@href^= ""] img').parent().click(function () {
            var linkz = $(this).attr("href");
            if(linkz.toLowerCase().indexOf("http: //www.website.com") >= 0) {
                window.open($(this).attr("href"));
                return false;
            } else {
                window.open("http://www.website.com/p/img.html?img=" + $(this).attr("href "));
                return false;
            }
        });
    });
</script>

To open all images in a new page passing the image url in the new link. but i'm getting

TypeError: $ is not a function.

I've tried to add jQuery(document) instead of the $(document) but then i got the

$(&#39;a[@href^=&quot;&quot;] img&#39;) TypeError: $ is not a function

here.

2
  • 5
    '$ is not a function' is usually a sure sign that you've forgotten to include the jquery library Commented Mar 28, 2013 at 1:59
  • How did you include jQuery into the page? Commented Mar 28, 2013 at 2:00

4 Answers 4

1

Either you didn't include jQuery, or else you ran noConflict() and it released control of $.

http://api.jquery.com/jQuery.noConflict/

If you used noConflict, you just need to use jQuery() throughout, including jQuery('a[@href^=""] img').

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

Comments

0

It looks like you're not including jQuery correctly as the browser doesn't know what $ is. Make sure you include something like this in <head> to include jQuery:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

Comments

0

you havent added the jquery add this at <head></head>

  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

if you are testing locally , and you have a llow bandwith , then download the script one time ** http://code.jquery.com/jquery-1.9.1.min.js **to your folder and use
<script src="jquery-1.9.1.min.js"></script>

Comments

0

Try this;

<script language="JavaScript" type="text/javascript" src="jquery/jquery.js"></script>
<script>
    jQuery.noConflict();
    (function ($) {
        function readyFn() {
            // Set your code here!!
        }

        $(document).ready(readyFn); 
    })(jQuery);

</script>

Or in your case:

<script language="JavaScript" type="text/javascript" src="jquery/jquery.js"></script>
<script>
    jQuery.noConflict();
    (function ($) {
        function readyFn() {
             $('a[@href^= ""] img').parent().click(function () {
             var linkz = $(this).attr("href");
             if(linkz.toLowerCase().indexOf("http: //www.website.com") >= 0) {
                 window.open($(this).attr("href"));
                 return false;
             } else {
                 window.open("http://www.website.com/p/img.html?img=" + $(this).attr("href"));
                 return false;
             }
        });
        }

        $(document).ready(readyFn); 
    })(jQuery);

</script>

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.