Getting an array of class names starting with string
Okay, I have code, it works. This is more of a learning jQuery thing for me because I couldn't find a shorter way of doing it. I'm still learning who's responsibility it is for what.
Is there a quick jQuery one liner to return (as an array) all class names that start with "{insert_string_here}"
The equivalent of the following:
Code:
var response = $( "*[class^='arete']");
var myClassArray = [];
for( var ix=0; ix < response.length; ix++)
{
myClassArray[ ix] = $( response[ ix]).attr( 'class');
}
You're going to have to explain that one to me, from what I read, get is just a short hand for an ajax call. I'm looking specifically for the class names.
Just clicked your link, that still gives me the elements rather than the values of class. I use the non-jQuery return value instead of get(), same difference on that part though.
Just clicked your link, that still gives me the elements rather than the values of class. I use the non-jQuery return value instead of get(), same difference on that part though.
There's not really a "one-liner." Although the following code could fit into one line, it's still an iterative command (loop).
Code:
var response = [];
$("*[class^='arete']").each(function (){
response.push(this.className);
});
Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.
Bookmarks