[support] l() function and javascript function

Dale McGladdery torelad at gmail.com
Tue Mar 31 16:53:56 UTC 2009


I'm by no means an expert in this area, but my understanding is that
the current best practice is using JQuery. I certainly consider it
best practice!

You'd add a CSS class, id, or attribute to your link (which ever is
most appropriate):
l($picture, "blog/$row->uid", array('title' => t('View user
profile.'), 'attributes' => array('class' =>'myclass'))

Actually, since the "$text" parameter is HTML (an img tag), I think
you'd need to set the html option true:
l($picture, "blog/$row->uid", array('title' => t('View user
profile.'), 'html' => TRUE, 'attributes' => array('class'
=>'myclass'))

Then you'd use JQuery along these lines:

$(document).ready(function(){
  $("a.myclass").click(function(event){
    // Your code
    return false;
  });
})

Sorry, I don't have any good references handy. I'm sure it wouldn't
take you long to find some good examples via Google.


On Tue, Mar 31, 2009 at 4:50 AM, Aldo Martinez Selleras <aldo at caonao.cu> wrote:
> how can i insert javascript functions in diferent events on my link created
> with l() function???
>
> i have this
>
> l($picture, "blog/$row->uid", array('title' => t('View user profile.'))
>
> this create a html code like this
>
> <a href="?q=blog/1" title="View user profile."><img
> src="http://URL_DOMAIN/files/avatar_selection/batman_1.jpg"
> alt="username&#039;s profile" title="username&#039;s profile"  /></a>
>
> and i need add some events...
>
> <a href="?q=blog/1" title="View user profile."
>
> onclick="get_show('+SOME_VAR+')"
> onmouseout="usercardget_hide()" >
>
>
> <img src="http://URL_DOMAIN/files/avatar_selection/batman_1.jpg"
> alt="username&#039;s profile" title="username&#039;s profile"  /></a>
>
> how can do this???
>
> thks in advanced
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>


More information about the support mailing list