I'd like the count the element on the page with the name :
Then I'd like get element MyElement
Thanks,
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
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.
jQuery uses: . append(); and . remove(); functions to accomplish this task. We could use these methods to append string or any other html or XML element and also remove string and other html or XML elements from the document.
The :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
var elements = $('[name^=MyElement]');
var length = elements.length;
If you want some more advanced filtering, you can filter all the dom nodes by matching your own rules :
var elements = $('[name]').filter(function(){
return /^MyElement_\d+$/.test($(this).attr('name'));
});
Use starts with selector
:
$('[name^="MyElement"]').length
better using
$('input[name$="name"]')
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