2

How to insert a div from one page into a div on current.

My method using .Load below was working but has stopped and I am unsure why.

$("#button").on('click', function() {
    $("#div").load('../url.aspx #div2');
});
DreamTeK
  • 32,537
  • 27
  • 112
  • 171

2 Answers2

3

The .load() you are using isn't deprecated - you are thinking of the load event.

In regard to your code - it should be working. You mentioned that it worked sometimes when trying with on() but not with it's shortcut click() - maybe you can try refreshing your browser cache or look at other parts of your code that you feel may be causing this (maybe what you're trying to load)?

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • 2
    I believe this is not the `load` to which the question is referring. – James Montagne Apr 03 '13 at 15:05
  • You misunderstood question :) – karaxuna Apr 03 '13 at 15:05
  • @user125697 How does this make any difference at all? @DreamTek accepted the answer, implying that it fixed his problem, but I fail to see how that's possible as `click` simply calls `on`. – James Montagne Apr 03 '13 at 16:43
  • Apologies @user125697 for delayed response. It appears you are right it did not fix my issue as it has now reoccurred. I assume it temporarily fixed due to some kind of caching. So the question remains. I really cannot work out what I have changed to break it. – DreamTeK Apr 04 '13 at 15:52
  • I have had a bonfire with my entire cache it definitely gone. So the code above is correct? – DreamTeK Apr 04 '13 at 15:55
  • @DreamTeK Yeah the code above is fine, does it still work sometimes? what are you actually loading? – dsgriffin Apr 04 '13 at 15:59
  • A gridview from another page. It does not work at all now although I have been cleaning up my js. – DreamTeK Apr 04 '13 at 16:02
  • @DreamTeK You've console.log'd inside of the click event to check whether it's the click itself or the load()? if it's the load, maybe an issue with the url or the gridview – dsgriffin Apr 04 '13 at 16:04
  • Thank you for helping. You are correct it was another part of my javascript further up causing everything after to fail. Much appreciated. – DreamTeK Apr 05 '13 at 07:21
  • @DreamTeK No problems man, glad you got it fixed! – dsgriffin Apr 05 '13 at 07:38
1

The event load is deprecated as of 1.8.

The load which you are asking about is not deprecated and can still be used without worry.

If for some reason you still want to replace load, you can use any number of other methods: ajax, get, etc.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
  • Thanks, please then can you assist why my code as added above works fine in jquery 1.8 but fails when I switch to 1.9.1 – DreamTeK Apr 03 '13 at 15:20
  • Well, for one, even if it were deprecated, that would not break code. Deprecated simply means it is not suggested to use it as it will be removed in the future. Deprecated methods still work. 2nd, I would need more information to even begin to answer why that stopped working. It looks fine to me. Do you get any errors? – James Montagne Apr 03 '13 at 15:24