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

JavaScriptAJAX

Avatar of undefined
Last Comment
error77
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
leakim971
Flag of Guadeloupe image

$("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
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of error77
error77

ASKER

Thanks !!!
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo