Solved

where is this syntax error coming from?

Posted on 2013-05-15
9
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
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…
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)

696 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