Solved

where is this syntax error coming from?

Posted on 2013-05-15
9
183 Views
Last Modified: 2013-05-15
I have a function like that someone here helped me with. This is the original function

$(document).live('pageinit', function () {
		
	$(window).bind('pageshow', function () {
		addBodyClass();
	});
	
	function getActiveSec(){
		return $('section.ui-page-active').attr('id');
	}
	function addBodyClass(){
		$('body').attr('class', getActiveSec());
	}
});

Open in new window


And I replaced it with "on" instead of "live". I get a syntax error at the last line but not sure how to fix it.  It looks like the curly brackets and paranthesis all match..so not sure

This is the new one:

$(document).on('pageinit',function(){
    addBodyClass();
	});
	
	function getActiveSec(){
		return $('section.ui-page-active').attr('id');
	}
	function addBodyClass(){
		$('body').attr('class', getActiveSec());
	}
 });

Open in new window

0
Comment
Question by:Camillia
  • 5
  • 3
9 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
Comment Utility
remove line 11?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
Comment Utility
$(document).ready(function() {
	addBodyClass();
});
	
function getActiveSec(){
	return $('section.ui-page-active').attr('id');
}
function addBodyClass(){
	$('body').attr('class', getActiveSec());
}

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
The orig code had line 11 and it was working fine. Let me try without it.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Ignore my comment it's exactly what leakim has pointed to. I just changed to document ready is the only difference
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Author Comment

by:Camillia
Comment Utility
Howcome line 11 was in the orig code (someone else has coded this) but i need to remove it in the new one?? Let me try it and see if it works without it.
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
yeah, that was it. Not sure why the orig had it but the revised one doesnt. It works tho
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
I think it's because i missed one line

$(window).bind('pageshow', function () {

so it should be

$(document).on('pageinit',function(){
 $(window).bind('pageshow', function () {
    addBodyClass();
      });
      
      function getActiveSec(){
            return $('section.ui-page-active').attr('id');
      }
      function addBodyClass(){
            $('body').attr('class', getActiveSec());
      }
});
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
I didn't deserve any points
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
yes, you did. You took the time to contribute.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

728 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

11 Experts available now in Live!

Get 1:1 Help Now