Solved

Unexpected identifier in this line of code

Posted on 2013-06-10
2
383 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

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
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 …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now