Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery .attr and IE7

Posted on 2009-07-13
10
Medium Priority
?
1,322 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Defunct-Exodus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 24842392
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
 

Author Comment

by:Defunct-Exodus
ID: 24842619
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
 
LVL 82

Expert Comment

by:hielo
ID: 24844497
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
Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

 

Author Comment

by:Defunct-Exodus
ID: 24849548
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
 
LVL 82

Expert Comment

by:hielo
ID: 24852049
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
 

Author Comment

by:Defunct-Exodus
ID: 24852168
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
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 24852520
>>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
 

Author Comment

by:Defunct-Exodus
ID: 24852574
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
 

Author Comment

by:Defunct-Exodus
ID: 24852637
Never mind, Trying that now i had a commented out the a portion.

Trying it now to see if it works.
0
 

Author Closing Comment

by:Defunct-Exodus
ID: 31602885
Damn i can not believe i missed that, I am a dumbass

Thanks for the help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question