Solved

Unexpected identifier in this line of code

Posted on 2013-06-10
2
391 Views
Last Modified: 2013-06-10
I'm new to JQuery and trying to get this example going

https://github.com/tuupola/jquery_lazyload#readme

I downloaded the jquery library, added class ="lazy". But now, I added this line of code
$("body").append("<script>$("img.lazy").lazyload();</script>"); 

Open in new window


to a .js code that's already in the project but it throws an error : unexpected identifier

not sure why.
init: function() {
				// register initializations here
				
				// quick view dialog div
				jQuery("<div/>").attr("id", "QuickViewDialog").html(" ").appendTo(document.body);
				
				// bonus product dialog div
				jQuery("<div/>").attr("id", "BonusProductDialog").html(" ").appendTo(document.body);
				
				
				$("body").append("<script>$("img.lazy").lazyload();</script>"); 
	
				// micicart object initialization
				this.minicart.init();
				
				// execute unobtrusive js code
				this.execUjs();

Open in new window

0
Comment
Question by:Camillia
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39235609
Hi,
this is because of a syntax error. The second double quotes will close the string, and then the rest will be the unexpected identifier.
Try this
 $("body").append('<script>$("img.lazy").lazyload();</script>');
0
 
LVL 7

Author Comment

by:Camillia
ID: 39235624
let me try. thanks for your help.
0

Featured Post

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.

Question has a verified solution.

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

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)

829 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