Jquery selectors

javascript, jquery, jquery-selectors

Solution

http://api.jquery.com/category/selectors/

$('input[type=button][name^=my-][name$=-press]').click(function() {
   // code
})

To assign event to elements dynamically, use `on` http://api.jquery.com/on/ and supply your selector as the second argument to properly `delegate` event.

$('#container').on('click', 'input[type=button][name^=my-][name$=-press]', function() {
   // code
})

Assuming you are wrapping your inputs on `#container`, otherwise replace `#container` with `body`, but it's always preferable to select the closest ancestor of the `selector`

Problem

Need a little help with my jquery here I want all my button with a name starting with "my-" and finishing with "-press" to have a "click" event. ``` <input type="button" id="my-button-x-press" name="my-button-x-name-press" /> ``` Buttons dynamically added to DOM should have the same event.

Original source