Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery selectors don't work

I have the following input on my page:

<input type="text" name="r1" />

I am trying to select it with JQuery, using $("[name='r1']"), and for some reason it returns null. Ok, fine, the title is misleading in that it is me that is doing something wrong; can you tell me what?

EDIT:

$('input[name="r1"]') doesn't work either. Also, sorry for the typo.

like image 975
Bluefire Avatar asked Mar 19 '26 13:03

Bluefire


1 Answers

Last EDIT

Working DEMO

Html Code

<input type="text" name="r1" />​

Jquery Code

$(document).ready(function() {
   alert($('input[name="r1"]').length);
});​

OLD Updates

you have typo error here you are trying to find r2 element which is not there just update code like $("[name='r1']")

or

to find it proper way you should do as below

$("input[name='r2']") instead of $("[name='r2']") only

EDIT

According to you edited question you should check example over here : Attribute Equals Selector [name="value"]

EDIT

for proper check you can do like this

$(document).ready(function() {
   alert($('input[name="r1"]').length);
});
like image 98
Pranay Rana Avatar answered Mar 21 '26 03:03

Pranay Rana



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!