Forum: Rails Spinoffs (closed, excessive spam) Targeting Element in a span and with class name

D3d6222693e76051adbb75fcc6576a66?d=identicon&s=25 Max (Guest)
on 2008-06-11 06:53
(Received via mailing list)
Hey guys, I am trying to target error class elements with Prorotype. I
am using it with the CakePHP framework so adding IDs will be difficult
and I'd rather not modify the core cakephp functions. Here's my sample
HTML:
<form id="LinkEditForm" method="post" action="/sourcing/links/edit/
29"><fieldset style="display:none;"><input type="hidden"
name="_method" value="PUT" /></fieldset>
<fieldset>
<legend>Name</legend>
    <span>

        <label for="LinkName">Name</label><input name="data[Link]
[name]" type="text" maxlength="20" size="20" class="req"
value="Maxmie" id="LinkName" /><div class="error-message">TEST2</
div>
    </span>
    <span>
        <label for="LinkEmail">Email</label><input name="data[Link]
[email]" type="text" size="20" class="req" maxlength="40"
value="max@mxime.com" id="LinkEmail" /><div class="error-
message">TEST</div>
    </span>
</fieldset>
<div class="submit"><input type="submit" value="Submit" /></div></
form>

Now, I want to be able to target the error-message divs per span. Is
there a way to do that?  GetElementByClassName has been deprecated and
it doesn't really help me anyway. I'm pretty sure what I'm asking is
impossible but I also know there are very smart people on this mailing
list. So, targeting the error-message div that comes right after a
certain input id is possible?

Max
F1fcf834ddad415f60d29c87cc10d4d4?d=identicon&s=25 kangax (Guest)
on 2008-06-11 08:23
(Received via mailing list)
Very possible.

// to select all elements with class error-message
$$('.error-message');
// to select all elements with class error-message which follow
element with id LinkEmail
$$('#LinkEmail + .error-message');

- kangax
This topic is locked and can not be replied to.