l() function and javascript function
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's profile" title="username'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's profile" title="username's profile" /></a> how can do this??? thks in advanced
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@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's profile" title="username'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's profile" title="username's profile" /></a>
how can do this???
thks in advanced -- [ Drupal support list | http://lists.drupal.org/ ]
You can also do 'attributes'=>array('onclick'=>'functionaname(arguments)'). That works better if you have a bunch of links that will get the function. Jamie Holly http://www.intoxination.net http://www.hollyit.net Dale McGladdery wrote:
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@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's profile" title="username'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's profile" title="username's profile" /></a>
how can do this???
thks in advanced -- [ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
participants (4)
-
Aldo Martinez Selleras -
Dale McGladdery -
Fred Jones -
Jamie Holly