Austin Cheney wrote:
> Scott Sauyet wrote:
>> On the other hand, can you find any better way to mimic `p.foo` than
>> the following?:
>
> I would just use //p[@class = "foo"]
> Of course, this looks for a class attribute whose value is only "foo".
> Outside of jQuery I see absolutely no value in supplying multiple values
> to a class attribute.  

Funny the different things that we find essential.  I use multiple
classes all the time for styling and for JS-hooks.

> But if you did you could use this XPath: p[contains(@class, 'foo')]

but that matches <p class="football"/> and <div class="villainy-
afoot"> which is unwanted.

> It's not quite as simple as p.foo, but it's not challenging either.  It
> does beg the question: jQuery aside why would I ever use that except if
> I did not know the full class value?

Do you work only with static HTML?  I work with dynamically-generated
and continually modified markup.  I can never count on knowing the
whole class value until I already know the node.

>> The only one of your list that I miss is parent.  And that only
>> rarely.
>
> I need access to ancestors all the time.  Consider this example:
> <div class="box">
>     <h3>Some title</h3>
>     <p class="buttons">
>         <button onclick="myfunction(this)">Trigger</button>
>     </p>
> </div>
>
> The button click triggers an action.  How do I find that h3 element from
> The button and not other h3 elements using a CSS selector?  Its common
> for an element generating an event to look to the status of some nearby
> ancestor element, such as if the class on the div element has changed
> value.  This can be summed up by saying I don't know what to do in the
> absence of my family.

I'm curious how you would do that with XPath inside myfunction.
`this` would refer to the button which has no id or other obvious way
to select the h3.  How do you do it?

  -- Scott

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to