0

I have multiple input elements like this

<input type="submit" name="top[1]" value="A"><br>
<input type="submit" name="top[2]" value="B">

the id's are added dynamically. How can I select all input's with name top[*] ?

The following jQuery code does not work in my case:

$('input[name="top[]"]').click(function(e){
    alert("Hello");
    e.preventDefault();
});

It would work, if I remove the numbers from the top array. Here is the corresponding jFiddle. How can I get it working with keeping the fixed id's in my input fields?

1 Answer 1

2

You can match with regex (the Attribute Starts With Selector):

$('input[name^="top"]')
Sign up to request clarification or add additional context in comments.

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.