error77
asked on
Javascript code not working ... assistance needed
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("l ink2").set Attribute( "href",str Link);
.......
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
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("l
.......
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry it got added twice for some reason but they are both the same one.
where do you include the external javascript ?
ASKER
It worked after changing the position where the js file was included.
Thanks :)
Thanks :)
ASKER
It's supposed to show the alert message but nothing happens..
Here is the code
Open in new window
Open in new window