Solved

Jquery not working in Safari

Posted on 2013-12-05
10
313 Views
Last Modified: 2013-12-06
Hi,

I have a jquery function that works in FF, IE and Chrome but wont work in safari

<script type="text/javascript">
$(document).ready(function(){
    $('#<!--$ tdcDateID-->').click(function(){
        $(this).next().toggle();
                 
        $(this).html($(this).text() == 'Less' ?'More' : 'Less');
        $('#<!--$ tdcLocationID -->').toggle();
        
    });
})
</script>


                         <a id="<!--$ tdcDateID-->">More</a>
                               <div style="width:80px;" id="<!--$tdcDateID-->" class="moredates data-collapsed="true">  

Some info....
</div>

Thanks for the help!

Open in new window

0
Comment
Question by:smfmetro10
  • 5
  • 4
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39699862
set a test page here as SIMPLE as you can : http://jsfiddle.net/
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39699902
Your identifier in this statement...

<a id="<!--$ tdcDateID-->">More</a>

is formatted as an HTML comment.  I'm surprised your code works in any browser.  In particular because I think javascript expects a letter as the first character.  What happens if you use just...

<a id="tdcDateID">More</a>
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39700080
In the Firefox Error Console, I get

[19:07:56.625] Error: Syntax error, unrecognized expression: #<!--$ tdcDateID--> @ http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:4

and it doesn't work.  If I put 'tdcDateID' in for the 'id', it does work, both in Firefox on my PC and Safari on my MacBook Pro.
0
 

Author Comment

by:smfmetro10
ID: 39701360
<!--$ tdcDateID--> is an Idoc script variable.
0
 

Author Comment

by:smfmetro10
ID: 39701420
I set up a test fiddle... Don't know if it will help as there are a lot of Idoc script variables in the function.  Viewing the source on safari confirms that the variables are being picked up though.

http://jsfiddle.net/smfmetro/DR5mq/
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39701630
It doesn't help because the "Idoc script variables" are not valid by themselves in javascript.  If you could give us an example from the 'View Source" that is not working then we might be able to figure it out.
0
 

Author Comment

by:smfmetro10
ID: 39701837
OK- thanks for the help!

This is straight out of the view source of safari:

<script type="text/javascript">
     $(document).ready(function(){
    $('#CON_ID_004633_1').click(function(){
   $(this).html($(this).text() == '[-]' ?'[+]' : '[-]');
        $('#CON_ID_004633_B').toggle();
         $('#CON_ID_004633_A').toggle(); 
    });
})
</script>
<a id="CON_ID_004633_1">[+]</a><span style="color:#959595;">&nbsp;&nbsp;&nbsp;&nbsp;Sep 5</span>
                               <div style="width:80px;" id="CON_ID_004633_A" class="moredates" data-collapsed="true">   
						<span style="color:#959595;">Oct 5</span>
						<br />
						<span style="color:#959595;">Dec 5</span>
						<br />
				</div>

   <div style="width:135px;" id="CON_ID_004633_B" class="moredates" data-collapsed="true"> 
					
						<span style="color:#959595;">CA - San Francisco</span><br />
						<span style="color:#959595;">OR - Portland</span><br />
			</div>

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39702000
This is the demo page I made from your code and it works in Firefox on my PC and Safari on my MacBook Pro.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#CON_ID_004633_1').click(function(){
			$(this).html($(this).text() == '[-]' ?'[+]' : '[-]');
			$('#CON_ID_004633_B').toggle();
			$('#CON_ID_004633_A').toggle(); 
			});
	})
</script>
</head>
<body>
<a id="CON_ID_004633_1">[+]</a><span style="color:#959595;">&nbsp;&nbsp;&nbsp;&nbsp;Sep 5</span>
                               <div style="width:80px;" id="CON_ID_004633_A" class="moredates" data-collapsed="true">   
						<span style="color:#959595;">Oct 5</span>
						<br />
						<span style="color:#959595;">Dec 5</span>
						<br />
				</div>

   <div style="width:135px;" id="CON_ID_004633_B" class="moredates" data-collapsed="true"> 
					
						<span style="color:#959595;">CA - San Francisco</span><br />
						<span style="color:#959595;">OR - Portland</span><br />
			</div>
                                            

Thanks for the help!
                                  
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:smfmetro10
ID: 39702138
Yeah I hear ya. Works for me too. Safari must be getting tangled up somewhere else in the code... OK -  thanks!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39702185
You're welcome, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now