Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count dynamic number of input elements on dom using jquery

How can count all input elements with has id which starting with (myInputElem) inside dom using jquery. So there will be dynamic number of input elements like

<input id="myInputElem1" type="text" value="Eleme1">
<input id="myInputElem2" type="text" value="Eleme2">
..
<input id="myInputElemx" type="text" value="Elemex">

So I just need to count them.

like image 254
user1765862 Avatar asked Dec 04 '22 03:12

user1765862


2 Answers

You can use the attribute starts with selector and then get the length

$('[id^="myInputElem"]').length
like image 178
adeneo Avatar answered Dec 09 '22 13:12

adeneo


use attribute starts with selector ^.

If you want to use the ends with selector, use $

$("[id^='myInputElem']").length;
like image 24
Anoop Joshi P Avatar answered Dec 09 '22 14:12

Anoop Joshi P