• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

where is this syntax error coming from?

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
Camillia
Asked:
Camillia
  • 5
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
remove line 11?
0
 
GaryCommented:
$(document).ready(function() {
	addBodyClass();
});
	
function getActiveSec(){
	return $('section.ui-page-active').attr('id');
}
function addBodyClass(){
	$('body').attr('class', getActiveSec());
}

Open in new window

0
 
CamilliaAuthor Commented:
The orig code had line 11 and it was working fine. Let me try without it.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
GaryCommented:
Ignore my comment it's exactly what leakim has pointed to. I just changed to document ready is the only difference
0
 
CamilliaAuthor Commented:
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
 
CamilliaAuthor Commented:
yeah, that was it. Not sure why the orig had it but the revised one doesnt. It works tho
0
 
CamilliaAuthor Commented:
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
 
GaryCommented:
I didn't deserve any points
0
 
CamilliaAuthor Commented:
yes, you did. You took the time to contribute.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now