I have a markup like this:
<div class="classA classB">the content</div>
What I would like is a selector that selects all of the divs that start with classA and I did this:
$("div[class^='classA'");
but since I (for example) have also classes like:
<div class="classAsuffix">
that selector would grab this div also, and I do not want that.
So, I want a selector that will get me all of the divs that do start with classA but then after that have a space so in general: give me all divs which have “classA (space) someOtherClass”.
I hope I’m clear with my request. Thank you for your help!
Oh, forgot tot mention: I tried this:
$("div[class^='classA ']") but it doesn't work...
The quotes around your value should be double quotes, not single quotes.Actually, it doesn’t seem to matter. So:…which works with the latest jQuery. It matches an element with a
classattribute starting with"classA "and so doesn’t matchdiv class="classA"but does matchdiv class="classA classB". But your version with single quotes works too. I’ve tried Chrome 11 (Linux & Windows), Firefox 3.6 (Linux), Firefox 4.0.1 (Windows), IE6, IE7, IE9, Opera 11 (Linux & Windows), and Safari 5 (Windows). I’ve tried jQuery 1.6.1 (the links above are to the “latest”), and jQuery 1.5.2. All gave the same result, finding only what I understand you want it to find.But — and this is slightly off-topic — I’d take a step back and look hard at why this need is coming up. It’s very unusual, which suggests there may be a better approach… Without knowing the underlying need, though, I could be wrong there.