jQuery Firebug console output question
Here is the contradictory output printed by jQuery in the Firebug console, when I was doing some debugging on a page that did not behave the way I had intended:
>>> $("input.rtnBtn")
null
>>> $('rbtn_4')
<input id="rbtn_4" class="rtnBtn" type="submit" value="Rate" name开发者_如何学Go="rate4">
as can be seen from the above, $("input.rtnBtn") is not finding anything - whilst the element with id 'rbtn_4' should clearly have been matched. Am I missing a trick here?
As an aside, although I am matching by class (because the id is generated at runtime), there is only one instance on the page - so I don't understand why jQuery can't match the element. Any ideas?
I believe that Firebug adds its own $
function as an alias for document.getElementById()
which is why $('rbtn_4')
found the element with that ID. (Why you need an element with the same class name as its ID is another question though...)
Anyway, Firebug usually doesn't override jQuery, but it happens to me occasionally. The solution is to just use jQuery(...)
in the console. You could also do $ = jQuery
.
精彩评论