jQuery .attr and IE7

Hello,

I am fairly new to jQuery and i am attempting to set a new attr to a <td> element, This works fine in Firefox but in IE7 it seems that the .attr is not being set correctly. I am attempting to set an onclick property to this.

Any suggestions as to why it is not being set in IE?

Thank you in advance.
$(td).attr("onclick","clicked_cell('"+year+"')");

Open in new window

Defunct-ExodusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
is td a reference to a DOM object?
Perhaps you meant to use a string::
$("td")

If not, try:
$("td").bind("click", function(){clicked_cell(year);});

Open in new window

0
Defunct-ExodusAuthor Commented:
Hielo,

I had actually tried that before and it does not work for what i need.  i am just not sure why .attr is not being assigned correctly in IE but works 100% in FF.

Thanks for your input though.
0
hieloCommented:
are you sure the bind() method doesn't work? I tested the attached code in IE6 an IE7 and it worked.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function(){
	$("span").bind("click",function(){alert(3)});
	$("div").bind("click",function(){alert(4)});
});
</script>
<span>hi</span>
<div>bye</div>
</body>
</html>

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Defunct-ExodusAuthor Commented:
Heilo,

Thank you for the response, The problem is that i am using a calendar script and modifying it so each TD has an onclick that returns it's day value.

Before i use .attr this is what i get for an alert on the onClick

function anonymous()
{
 date("2009/05/04')
}

after i set the attr value for onclick this is what i get
date('2009/05/04')

Not sure what the difference there is but the first one actually works
0
hieloCommented:
Yesterday I DID try with attr() and you are correct. It does not work with IE. But the bind method does work. So if there is a chance to achieve what you need, I guess bind() is the way to go. Is the calendar script publicly available? It's nearly impossible to help you if I can't replicate the problem.

Regards
0
Defunct-ExodusAuthor Commented:
Hielo,

Sorry about the lack of information, Yes the script is available here
http://arshaw.com/fullcalendar/

I have tried the bind option and it appears to prevent the calendar from working correctly.

Once again thanks.
0
hieloCommented:
>>The problem is that i am using a calendar script and modifying it so each TD has an onclick that returns it's day value.
Did you read the documentation?
http://arshaw.com/fullcalendar/docs/#triggered-actions


	<script type='text/javascript'>
 
	$(document).ready(function() {
	
		var d = new Date();
		var y = d.getFullYear();
		var m = d.getMonth();
	
		$('#calendar').fullCalendar({
			draggable: true,
 
			dayClick:function(dayDate){
				alert("Full date:"+dayDate);
				alert("Just today's date:"+dayDate.getDate())
				
				},
 
			events: [
				{
					id: 1,
					title: "Long Event",
					start: new Date(y, m, 6),
					end: new Date(y, m, 11)
				},
				{
					id: 2,
					title: "Repeating",
					start: new Date(y, m, 2)
				},
				{
					id: 2,
					title: "Repeating",
					start: new Date(y, m, 9)
				},
				{
					id: 3,
					title: "Meeting",
					start: new Date(y, m, 20, 9, 0)
				},
				{
					id: 4,
					title: "Click for Facebook",
					start: new Date(y, m, 27),
					end: new Date(y, m, 29),
					url: "http://facebook.com/"
				}
			]
		});
		
	});
 
 
	</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Defunct-ExodusAuthor Commented:
Heilo,

Yes i did, The on click only works with events on the day, I need this to report the selected date regardless of if there is an event or not.
0
Defunct-ExodusAuthor Commented:
Never mind, Trying that now i had a commented out the a portion.

Trying it now to see if it works.
0
Defunct-ExodusAuthor Commented:
Damn i can not believe i missed that, I am a dumbass

Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.