Reputation: 417
I've got a simple HTML form and for some reason jQuery cannot find the element I'm looking for.
HTML:
<form id="form">
<fieldset>
<table>
<tr class="row">
<td class="label">Street</td>
<td class="field"><input type="text" size="50" value="" id="s.street"></td>
</tr>
</table>
</fieldset>
<fieldset>
<tr class="row">
<td class="label">Street</td>
<td class="field"><input type="text" size="50" value="" id="b.street"></td>
</tr>
</table>
</fieldset>
</form>
jQuery :
$(document).ready(
function() {
$("input[id='s.street']").keyup(function() {
$('#b.street').val($(this).val());
});
});
I get no errors in the console log.
Upvotes: 3
Views: 6487
Reputation:
ID's should be unique, so you shouldn't have to filter with the input tag. Additionally, you need to add an escape sequence before the .
in your ID name. $('#s\\.street')
is the correct selector. I would actually suggest not using the .
...
Upvotes: 2
Reputation: 17759
Sizzle (the javascript selector library that jQuery implements) will see the s.street
as an element s
or b
with a class of street
. as opposed to an element with id of s.street
.
Upvotes: 0
Reputation: 12228
If the element HAS to have that exact id, use:
$('#b\\.street')
Upvotes: 4
Reputation: 43810
YOu have a problem in your naming convention. replace the .
in the name to a hyphen.
So:
<input type="text" size="50" value="" id="s.street">
Becomes
<input type="text" size="50" value="" id="s-street">
and you select in with jquery like so:
$("#s-street");
Upvotes: 0
Reputation: 1420
your id names conflict with the jquery selector syntax.
When defining an id for an element do not use the # . or any spaces within your ID
Upvotes: 0
Reputation: 6051
from here: What are valid values for the id attribute in HTML? it looks like jquery has trouble with ids that have periods and colons. so try removing those and see if it works.
Upvotes: -2