Forum: Rails Spinoffs (closed, excessive spam) Class property

950af1c36225d95580d463ec728439cc?d=identicon&s=25 AlannY (Guest)
on 2008-06-13 18:32
(Received via mailing list)
I have a DIV in the following format: <div class="MyClass[Param]">

I want to parse it. Which approach is better? I can found all divs
with $$('.MyClass'), but how to find [Param] string?

Or, for me, it's better to use <div class="MyClass" id="Param"> and
then found all $$('.MyClass').each(function(el) { el.id })?

I think, the first method is better, than second one. But I don't know
how to implement it with Prototype.

Thank you.
F490e41cd5de1393a9f6958b70dae6ab?d=identicon&s=25 Frederick Polgardy (Guest)
on 2008-06-13 18:53
(Received via mailing list)
Not sure if [] is valid in a css class.  Why not use two classes?

<div class="MyClass Param">

$$('.MyClass.Param')

or

$$('.MyClass.' + someParam)

-Fred

On Fri, Jun 13, 2008 at 11:31 AM, AlannY <m@alanny.ru> wrote:

> how to implement it with Prototype.
>
> Thank you.
>
> >
>


--
Science answers questions; philosophy questions answers.
F1fcf834ddad415f60d29c87cc10d4d4?d=identicon&s=25 kangax (Guest)
on 2008-06-13 19:03
(Received via mailing list)
$$('[class="MyClass[Param]"]') should work.
Multiple classes is not a bad idea, just remember that IE ignores such
css declarations (and applies only last class' rules)

- kangax
950af1c36225d95580d463ec728439cc?d=identicon&s=25 AlannY (Guest)
on 2008-06-13 19:33
(Received via mailing list)
Param is a non constant value ;-)

For example, <div class="MyClass[4342]"> I want to extract: Element
(div), class name ("MyClass") and params ("4342"). So on.
0147e858c76509f264daca9a460afd7a?d=identicon&s=25 Dan Dorman (Guest)
on 2008-06-13 19:36
(Received via mailing list)
On Fri, Jun 13, 2008 at 11:32 AM, AlannY <m@alanny.ru> wrote:
>
> Param is a non constant value ;-)
>
> For example, <div class="MyClass[4342]"> I want to extract: Element
> (div), class name ("MyClass") and params ("4342"). So on.

If the value of param is unique to an element, I'd move it to the id
attribute.

:Dan
F1fcf834ddad415f60d29c87cc10d4d4?d=identicon&s=25 kangax (Guest)
on 2008-06-13 22:02
(Received via mailing list)
For a precise matching:

$$('div').findAll(function(el) {
  return /^MyClass\[\d{1,4}\]$/.test(el.className);
})

Though such approach does indeed seem weird.

- kangax
950af1c36225d95580d463ec728439cc?d=identicon&s=25 AlannY (Guest)
on 2008-06-14 09:16
(Received via mailing list)
Thanks a lot ;-) That's what I want ;-) Thanks ;-)
This topic is locked and can not be replied to.