This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes JQuery Selector Help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JQuery Selector Help needed" Watch "JQuery Selector Help needed" New topic
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: 60774
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 60774
    
  65

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: 15376
    
    6
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
 
Don't get me started about those stupid light bulbs.
 
subject: JQuery Selector Help needed
 
Similar Threads
problem when integrating jspell with tinyMCE editor
Displaying JSP in certain DIV tag
Can you read this?
How to show icons in Tree using DOJO 0.4
using CSS float attribute makes things 'leak' out of their containers ?