Solved

where is this syntax error coming from?

Posted on 2013-05-15
9
185 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
ID: 39169248
remove line 11?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 39169268
$(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
ID: 39169286
The orig code had line 11 and it was working fine. Let me try without it.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 58

Expert Comment

by:Gary
ID: 39169297
Ignore my comment it's exactly what leakim has pointed to. I just changed to document ready is the only difference
0
 
LVL 7

Author Comment

by:Camillia
ID: 39169301
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
ID: 39169330
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
ID: 39169373
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
ID: 39169448
I didn't deserve any points
0
 
LVL 7

Author Comment

by:Camillia
ID: 39169504
yes, you did. You took the time to contribute.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

777 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