troubleshooting Question

Javascript code not working ... assistance needed

Avatar of error77
error77 asked on
JavaScriptAJAXHTML
5 Comments1 Solution183 ViewsLast Modified:
Hi all,

I am having an issue with some code as it's not working for some reason. I wonder if anyone could spot what the problem is.

I'll explain:

In an external JS file I have this code:

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

Then I have some javascript for the link in the head that takes care of the link:

<script language="javascript">
      $(document).ready(function() {
      
         var thisyear = new Date().getFullYear();
       var strLink = "index2.php?mydate=" + thisyear + "-1-1";
       document.getElementById("link2").setAttribute("href",strLink);

.......


And finally the link:

<a id="link2" rel="external"> Link Here</a>


The links DO work ... the problem is that the code on the JS file is not working...

When I click on the link it should show the alert but it's not.

Can anyone help please?

Thanks






ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros