Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

Javascript detect ID clicked ?

Hi all,

Is it possible at all to detect if an id has been clicked?

For example: I want a link on a page containing an ID to be detected by javascript if it was click.

The javascript would look like this...

if (ID was clicked) {
   alert("id was clicked");
}

something like that anyway..

Can this be done?

Thanks

Avatar of jordanrynard
jordanrynard

The best way to do it would be to just add a class to an element once it has been clicked (ex. 'clicked'), and then check to see if that element has the class 'clicked' during your check.

Are you using a library like jQuery, or just straight up javascript?
Avatar of leakim971
$("a").click(function() { if( $(this).attr("id") == "ID" ) {
    alert("id was clicked");
}});

Open in new window


or if you create the link dynamically :

$("a").live("click", function() { if( $(this).attr("id") == "ID" ) {
    alert("id was clicked");
}});

Open in new window



Avatar of error77

ASKER

Looks perfect but I need to change the code in the plugin js file so I don't think I can use JQuery for this.

What would the pure javascript translation be please?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error77

ASKER

Thanks !!!