| Author |
JQuery Selector Help needed
|
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
|
|
Hello all,
I have a HTML snippet which looks like this.
I need to form a selector which selects all the elements starting until . Can someone help me on this?
Thanks,
Srikkanth
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
You can't. There is no way to select a range of elements in that way -- at least not with a single selector. You'll either need to specify multiple selectors for each individual element, or re-arrange the HTML to suit your selection needs.
I always prefer the latter. Structure the HTML intelligently, and the selectors become easy.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
|
|
Thanks for the quick response.
This HTML is generated by a third party . Probably I need to group the tags together (using java string manipulation or something). I was hoping that this could be achieved using some combination of selectors.
Thanks,
Srikkanth
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
Srikkanth Mohanasundaram wrote:I was hoping that this could be achieved using some combination of selectors.
It can. That was one of the approaches I said could work.
|
 |
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
|
|
Let us say i group the tags following the title paragraph (p with class name title), like this
Now, how should i form a selector to fetch the div followed by the title paragraph ? I guess something like this
$(".title + div"), but i also need to check the innerText of the title paragraph (I would want to select Title 1,Title 2 so on..).
Thanks for your help,
Srikkanth
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
documentation is helpful
http://docs.jquery.com/Selectors/contains
Eric
|
 |
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
|
|
Thanks for the pointer Eric.
This was the selector i was looking for . JQuery is simply awesome (Just a single line!!).Thanks for your suggestions Bear.
Thanks for your help,
Srikkanth
|
 |
 |
|
|
subject: JQuery Selector Help needed
|
|
|