Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery won't find element with ID Selector, but will find it with ID alone

Tags:

jquery

asp.net

I'm developing an ASP.NET app and using jQuery. I have a <div> element with the id='slider'. When trying to access the element using $('#slider'), it returns null, but when trying to access it without the selector, ie. $('slider') the element is returned.

What could be the reason for that?

like image 494
ml123 Avatar asked Dec 19 '25 22:12

ml123


1 Answers

If the selector doesn't match, then jQuery doesn't return null. So that's two counts of "Acting unlike jQuery" which suggests that the answer is: $ is not jQuery in your page.

Something else is redefining it. Possibly mootools or prototype.js (I'm not sure what either return if there is no matching element, but I'm pretty sure that both have a $ function that takes an id and not a CSS selector as the argument).

like image 178
Quentin Avatar answered Dec 22 '25 13:12

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!