• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Issue with Jquery Code while Content is loaded through ajax

Hi, I have the following code where i am making an ajax to the external page andoing it like this

<script>
$(document).ready(function(){
  $("button").click(function(){
    $.ajax({
              url:"demo_test.txt",
              success:function(html){
              source = $("#code").html();
              template = Handlebars.compile(source);
              $('#list').html(template(response));
    }});
  });
});
</script>

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
0
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
  • 4
  • 2
  • 2
1 Solution
 
GaryCommented:
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.
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
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
0
 
GaryCommented:
What is the css and what is the class you are trying to add.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
the css is:

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

so i am trying it like this:


$('#list').html(template(response)).addClass('listing');

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
0
 
Chris StanyonCommented:
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!!
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
i have solved i, it was a bad css issue
0
 
Chris StanyonCommented:
If you'd have just posted a link like we asked we could have told you that straight away!!
0
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
css was missing a closing braces so it was breaking in between
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now