4

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.

3 Answers 3

12

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

$('[id^="myInputElem"]').length
Sign up to request clarification or add additional context in comments.

Comments

4

use attribute starts with selector ^.

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

$("[id^='myInputElem']").length;

Comments

0

Even u can try this

$('[value^="Eleme"]').length

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.