Match the beginning of a Class or ID in jQuery

December 15, 2013 | Last tested: May 2015 | 749 views | Comments

Select an element that has an attribute Class or ID that starts with a given keyword.

For example.

Match all elements that has an attribute ID that starts with "member_".

[id^="member_"]

 

Bind the javascript click event to it.

$('[id^="member_"]').click(function(){
	console.log($(this).prop("id"));
});

 

Match all elements that has a Class attribute that starts with "member_".

[class^="member_"]

 

Related Tutorials


Must Read