jQuery ID starts with

JavascriptJquery

Javascript Problem Overview


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");
		});
		
		
	});
});

Javascript Solutions


Solution 1 - Javascript

try:

$("td[id^=" + value + "]")

Solution 2 - Javascript

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/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDG3View Question on Stackoverflow
Solution 1 - JavascriptNoneView Answer on Stackoverflow
Solution 2 - JavascriptŠime VidasView Answer on Stackoverflow