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.
on 2008-06-13 18:32
on 2008-06-13 18:53
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.
on 2008-06-13 19:03
$$('[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
on 2008-06-13 19:33
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.
on 2008-06-13 19:36
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
on 2008-06-13 22:02
For a precise matching:
$$('div').findAll(function(el) {
return /^MyClass\[\d{1,4}\]$/.test(el.className);
})
Though such approach does indeed seem weird.
- kangax