Issue with Jquery Code while Content is loaded through ajax

Posted on 2013-11-28
Last Modified: 2013-12-06
Hi, I have the following code where i am making an ajax to the external page andoing it like this

              source = $("#code").html();
              template = Handlebars.compile(source);

Now there a element which is called as

<div id="list"></div>

The response coming from the jquery is loaded in that div inside it,

so i want to apply a class to the internal code but it is nt reflecting, if itry to add the straight css property, it works but not the class, even i have defined the class in the css file
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
  • 4
  • 2
  • 2
LVL 58

Expert Comment

ID: 39683840
Are you are wanting to add a class name to the internal HTML or are you saying your CSS is not being applied?
Regardless you haven't given enough of your code to even know what the problem maybe - the ajax code is of no use.
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39683971
want to apply the class name to the internal html, i aplied successfully through addClass but the thing is it shows in firebug but style added to the class does not show up
LVL 58

Expert Comment

ID: 39683998
What is the css and what is the class you are trying to add.
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39684651
the css is:

.listing  { color: red; border:1px solid green; }

so i am trying it like this:


but it is not picking up the class

i even added the addClass before html, but no aval, if i add straight css, it works but not class
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39685357
Any chance of a link to a page that demonstrates the problem. We need to at least see the HTML of your page, the content of demo_test.txt, and your CSS file.

In the code above you're making an AJAX request to demo_test.txt but then doing nothing with the response. Is that your intention?

Your code assumes that the #code and #list elements are already in the document before the AJAX call, and that you are correctly loading the Handlebars script.

I'm making a lot of assumptions here because without seeing code, that's the best I can do!!
LVL 16

Accepted Solution

Gurpreet Singh Randhawa earned 0 total points
ID: 39689372
i have solved i, it was a bad css issue
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39689377
If you'd have just posted a link like we asked we could have told you that straight away!!
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39700554
css was missing a closing braces so it was breaking in between

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

632 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