Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Return elements where ID begins with a certain string

Tags:

I have a lot of <span> tags like this <span id='val_Title'></span> <span id='val_Name'></span>

I would like to return all the elements that begin with 'val_' and hide them.

How can I do this?

like image 546
Jon Avatar asked May 22 '09 09:05

Jon


People also ask

What does $() return in jQuery?

$() does not return the jQuery function, (which is $ itself,) but returns a wrapped set, with all those helpful methods on it.

How do I target a specific element in jQuery?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

What is '$' in jQuery?

$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.

How do I find the ID of a selected element?

getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.


1 Answers

Use attribute selectors

$(document).ready(function(){    $("span[id^='val_']").hide(); }); 
like image 155
Rafael Avatar answered Sep 25 '22 13:09

Rafael