On Feb 9, 11:43 am, cbmtrx <[EMAIL PROTECTED]> wrote:
> Thanks lihao.
>
> Actually, there are cases when there would be more than one "newdiv"
> following an "olddiv"...which means that the jquery .next identifier
> wouldn't always work. ie: It's not a 1:1 ratio. So I've been trying to
> find the most simple&elegant solution, without resorting to the old
> javascript functions...

You probably can use a container DIV to each group of <a/> and new/old
DIVs, then you can handle variable number of inside DIVs with jQuery
more easily.

> From what little I've learned so far, jquery seems to work mostly in
> one direction (JQ -> DOM) and it doesn't seem all that geared up for
> doing things the other way around (unless you use a plugin like
> metadata for passing vars, which isn't any simpler).

I think, we don't have to isolate jQuery from original Javascript, we
can still customize javascript functions and just use jQuery's great
feature of parsing DOM. From my understanding, as long as your data is
in DOM, you can always use jQuery to find them. so for the above
metadata example, we can use the tricks mentioned in Smith's post(for
simple cases, we don't really need a plugin), for example, we can use
'class' to deliever parameters and then use 'eval' and jQuery's
feature to extract these data:

<div id="test">
 <a href="#" class="{va : 'eee', vb : '1'}">click1</a>
   |
 <a href="#" class="{va : 'fff', vb : '2'}">click2</a>
   |
 <a href="#" class="{va : 'ggg', vb : '3'}">click3</a>
 <p>va : <span></span> </p>
 <p>vb : <span></span> </p>
</div>

<script type="text/javascript">
 var $DIV = $('div#test');
 $('a', $DIV).click(function() {
     var metadata;
     eval( "metadata = " + $(this).attr('class') );
     $('span:eq(0)', $DIV).html(metadata.va);
     $('span:eq(1)', $DIV).html(metadata.vb);
 });
</script>

We don't have to use the 'class' attribute though, we can use 'title'
or else for this trick :-)

Regards,
lihao(XC)

Reply via email to