We help IT Professionals succeed at work.
Get Started

Using $.get to mimic .load feature...

trg_dk asked
Last Modified: 2012-05-12
Hi Experts :)

On a page I'm toying with, I have made a function, that binds to the menu. So that when the user click the menu, the content is retrieved using $.get.

This is done, because the logo carousel that appears on every page, shouldnt get interupted by pageloads.

Any ways, the function works kind of. I need to get the content of 2 div's in the loaded html. Please see my attached code.

The problem is that I never get anything but null from the div #referenceMenu

To test it, you can visit the page (in danish) a http://koalit.dk/kailow

Click the menuitem "Hvem er vi" (number 3 from the bottom) - the real url for the page containing the div #referenceMenu are http://koalit.dk/kailow/hvem_er_vi.html

Any help will be appreciated - thanks guys :)
function ajaxifyMenu(){
	$("#nav a").bind("click", function(event){
		$("#nav .selected").removeClass("selected");
		var url = $(this).attr("href");
			console.log( html );
			$("#mainText").html( $(html).find("#mainText").html() );
			$("#referenceMenu").html(  $(html).find("#referenceMenu").html()  );

Open in new window

Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE