- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Jquery Selecting ID's
Hi All, I’m new to jQuery and have build a codepen for a hotel booking form that reveals sections of the form the more guest there are, worked fine in codepen, if you added number to adult, children and babies it adds them and reveals another section of the form.
http://codepen.io/Garypickles/pen/jofvL?editors=101
but when i moved it across onto my page, it stopped working, solved the problem, turned out my code would not select by ID if there was another in on the input.
ID=”total” worked
ID=”someotherid total” didn’t work
can anybody explain why?
My code works but looks a bit long winded, is there a shorter more elegant way to approach this? or for such a simple task is this OK
turned out my code would not select by ID if there was another in on the input.
ID=”total” worked
ID=”someotherid total” didn’t workcan anybody explain why?
Because “total” and “someotherid total” are not the same ID. If you need your code to select things with different IDs, use a .class
or [data-attribute]
selector instead.
MOD: dupe. please delete.
thank you, I was under the impression you could give multiple ID’s to one object by putting a space between them as you can with classes.
Nope. The id is the entire string.
If you need class names for another purpose, you can use those. Otherwise, data-*
attributes are most appropriate for what you’re doing.