jQuery ID starts with
I am trying to get all elements with an id starting with some value. Below is my jQuery code. I am trying to use a JavaScript variable when searching for items. But it does not work. What am I missing below? So the id 'value' am searching is the value of the clicked element
$(document).ready(function() {
$('input[name$="_chkmulti"]').click(function(){
var value = $(this).val();
$("td[id^= + value +]").each(function(){
alert("yes");
});
});
});
Solution 1:
try:
$("td[id^=" + value + "]")
Solution 2:
Here you go:
$('td[id^="' + value +'"]')
so if the value is for instance 'foo'
, then the selector will be 'td[id^="foo"]'
.
Note that the quotes are mandatory: [id^="...."]
.
Source: http://api.jquery.com/attribute-starts-with-selector/