Solved

Unexpected identifier in this line of code

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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 …
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)

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