I have that in my html
<input type="checkbox" id="1234">
<input type="checkbox" id="2345">
<input type="checkbox" id="3456">
<input type="checkbox" id="4567">
<input type="checkbox" id="5678">
And an list of id 1234 2345 3456
or #1234 #2345 #3456
I want to get all the element of the list whose id is in the list of id
I try $(":checkbox").attr('id', items_id);
and var items_cb = $(":checkbox[id='items_id']");
where items_id is the list of item, but it doesn't work.
The id must be unique. There can be only one element in the document with the given id . If there are multiple elements with the same id , then the behavior of methods that use it is unpredictable, e.g. document. getElementById may return any of such elements at random.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
To select multiple elements, you can use the querySelectorAll() method. Just like the querySelector() method, you usually use it on the document object.
Use the document. querySelectorAll() method to get all elements whose id starts with a specific string, e.g. document. querySelectorAll('[id^="box"]') . The method returns a NodeList containing all the elements that match the provided selector.
Just try to put all id's in selector separated by comma:
$('#1234, #2345, #3456')...
Code: http://jsfiddle.net/3df6W/
P.S. ID's shouldn't start with digits.
Try this
$('#1234, #2345, #3456')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With