Solved

Jquery not working in Safari

Posted on 2013-12-05
10
310 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
Comment Utility
set a test page here as SIMPLE as you can : http://jsfiddle.net/
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
<!--$ tdcDateID--> is an Idoc script variable.
0
 

Author Comment

by:smfmetro10
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
Yeah I hear ya. Works for me too. Safari must be getting tangled up somewhere else in the code... OK -  thanks!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome, glad to help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

771 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

14 Experts available now in Live!

Get 1:1 Help Now