Solved

Jquery not working in Safari

Posted on 2013-12-05
10
322 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

837 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