• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuery Selector Help needed

 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
documentation is helpful

http://docs.jquery.com/Selectors/contains

Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic