-2

I am trying to use jQuery.get(), since .load only loads the html snippet, but the jquery css isn't applied on this content.

$("#content").load("home.html", function() {
            });


$.get('home.html', function(data) {
            $('.content').html(data);
            alert('Load was performed.');
            });

When I type '#content' it loads an empty page. What means this data? Do I have to name something data to make it work?

Thanks!

3 Answers3

0
$.get('home.html', function(data) {
            $('.content').html(data);
            alert('Load was performed.');
            });

You seem to be referring to the target in two different ways. #content vs .content.

Possibly it should be

$.get('home.html', function(data) {
            $('#content').html(data);
            alert('Load was performed.');
            });
TGH
  • 38,769
  • 12
  • 102
  • 135
0

I think there is a problem in your selector in the get callback handler.

$.get('home.html', function(data) {
    $('#content').html(data);//Note #content, you are using .content
    alert('Load was performed.');
});
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
-1

load() and get() are very different functions, check out: AJAX jQuery.load versus jQuery.get

Check the path of "home.html" and take a look at the result (data) you get. I guess, your data in "home.html" is not what you or $.get() is expecting.

As already mentioned: maybe you confused ".content" and "#content"!

$.get('home.html', function(data) {
    alert("Result: " + data);
});
Community
  • 1
  • 1
Mr. B.
  • 8,041
  • 14
  • 67
  • 117
  • 1
    load() is just a shortcut for $.get() that also inserts the content, so they aren't that different ? – adeneo Jun 15 '13 at 16:39
  • @adeneo: as you already mentioned: they are different. Maybe not that different in your opinion, but they are! :) – Mr. B. Jun 15 '13 at 16:41