tags:

views:

58

answers:

3

Just starting using the Firebug console. I have a test script which I'll post below. I open up the Firebug console and type $("p"); this returns null. Its my understanding it should return all my p elements ie p, p.foo, p, p#bar. A conflict maybe or am I just using the console incorrectly?

<!DOCTYPE html>
<html>
<head>
  <title>Testing jQuery</title>
</head>

<body>
    <p>Hello World!</p>
    <p class="foo">Another paragraph, but this one has a class.</p>
    <p><span>This is a span inside a paragraph.</span></p>
    <p id="bar">Paragraph with an id.
    <span class="foo">And this sentence is in a span.</span>
    </p>

    <script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
    <script type="text/javascript"
        google.load("jquery", "1.4.2");
    </script>
</body>
</html>
A: 

Yes you are using the console correctly, when i open firebug and type $("p") it returns everry p element in the DOM.

Ben Robinson
A: 

You're using the console correctly. Even if jQuery can't find any results, it should return an empty object, not null.

Could you console.log($); to see if jQuery is loaded?

That should result in the jQuery function being returned:

function ( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context );
}
kander
+1  A: 

Hi,

What you used is an ID selector. If you have a selector with an id u should use $("ID").

What you want is an array of css selectors-> then you should use $$("selector") -> in your case: $$("p")

more information is to be found here

http://www.joehewitt.com/software/firebug/docs.php

I hope this helped :D

Nealv
Nealv - interesting! It appears both Firebug and jQuery use the dollar-function as a selector. It definitely explains why the topic starter was seeing the result he did, although the solution he was looking for was more regarding figuring out whether or not jQuery was loaded. Thanks for adding this answer, learned something today!
kander
It was my understanding that he needed help with firebug. anyway glad to be of service. I learn lots here every day :)
Nealv