Jump to content

I have hundreds of rows of links. I do not want links to have their URL addresses hardcoded into the pages via href when loaded in, rather keep it to a function and their destination confirmed by their ID, triggered by their class.

 

Link looks like:

<a id="111112" class="openCertLink" href="#">Line 1 - <b>Line 2</b>. ID: "111112"</a>

 

I've tried using the .click jQuery function like it works for everything else, yet here for links it's just a dud, doing nothing. All other suggestions online are outdated with security issues that aren't even allowed on browsers anymore, use ID's not classes or just 30 year old hardtyped href.

 

function:

$(".openCertLink").click(function(event){
    alert("Link away");
    // ...and so on
});

Annoying to be stuck on something so simple again. Anyone able to kick me into gear and remind me how to properly do this?

MAIN: Ryzen 7 5800X3D - Kraken X62 Rev 2 - STRIX X470-I - 3600MHz 32GB Kingston Fury - 250GB 970 Evo boot - 2x 500GB 860 Evo - 1TB P3 - 4TB HDD - RX6800 - Antec HCG Platinum - Manta - Silent Wings Pro 4's enjoyer

SetupZowie XL2740 27.0" 240hz - Roccat Burt Pro OG Corsair K70 browns - PC38X - Mackie CR5X's Mackie CR8S-XBT

Current build on PCPartPicker

 

 

HTPC: Ryzen 7 2700X - BeQuiet! Shadow Rock 3 - STRIX X570-F - 3200MHz 32GB Corsair Dominator - 250GB Exceria boot - 500GB SN730 - 1TB Sandisk 3D - 4TB HDD - Limited Edition Vega 64 - Corsair RM750x 80+ Gold - North - Alphacool Apex Stealth Metal - BeQuiet! Light Wings

SetupHisense 55E7NQ - Hisense HS205G

HTPC on PCPartPicker

Link to post
Share on other sites

$(document).ready(function(){
  $(".openCertLink").click(function(eventObject) {
    window.open("https://www.google.com/search?q=" + eventObject.target.id);
  });
});

This code works on my end. This opens a Google search for the ID of the anchor tag.

Edited by Ominous
Changed example
Link to post
Share on other sites

On 1/28/2025 at 11:12 AM, Ominous said:
$(document).ready(function(){
  $(".openCertLink").click(function(eventObject) {
    window.open("https://www.google.com/search?q=" + eventObject.target.id);
  });
});

This code works on my end. This opens a Google search for the ID of the anchor tag.

Thanks. You helped me confirm that jQuery wasn't actually to blame here as it works in it's own clean environment but something's making it either not react of follow logic.

 

Fault was that I had modified the classes in runtime. I should have done it a different way but basically I called $(document).ready before changing classes, so no surprise jQuery couldn't find these classes, cause they didn't exist at the time of the document being ready.

 

Without a whole rewrite of my page, I moved document ready to be called in a function, after which jQuery did detect now when the links were clicked.

 

It's these basic things that skip my mind and waste a productive day.

 

Thanks my dude.

MAIN: Ryzen 7 5800X3D - Kraken X62 Rev 2 - STRIX X470-I - 3600MHz 32GB Kingston Fury - 250GB 970 Evo boot - 2x 500GB 860 Evo - 1TB P3 - 4TB HDD - RX6800 - Antec HCG Platinum - Manta - Silent Wings Pro 4's enjoyer

SetupZowie XL2740 27.0" 240hz - Roccat Burt Pro OG Corsair K70 browns - PC38X - Mackie CR5X's Mackie CR8S-XBT

Current build on PCPartPicker

 

 

HTPC: Ryzen 7 2700X - BeQuiet! Shadow Rock 3 - STRIX X570-F - 3200MHz 32GB Corsair Dominator - 250GB Exceria boot - 500GB SN730 - 1TB Sandisk 3D - 4TB HDD - Limited Edition Vega 64 - Corsair RM750x 80+ Gold - North - Alphacool Apex Stealth Metal - BeQuiet! Light Wings

SetupHisense 55E7NQ - Hisense HS205G

HTPC on PCPartPicker

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×