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?
$() does not return the jQuery function, (which is $ itself,) but returns a wrapped set, with all those helpful methods on it.
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.
$ 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.
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.
Use attribute selectors
$(document).ready(function(){ $("span[id^='val_']").hide(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With