• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JQuery Selector Help needed

 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic