Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery how do I create a variable and use it in a selector?

Posted on 2009-05-14
2
Medium Priority
?
898 Views
Last Modified: 2012-08-13
I have some code that will pull data from another page and put it in a list item with an id that I specify.

  $(document).ready(function(){
      $("#buttonAdd").click(function() { GetContentFromAnotherPage(); });
      });

function GetContentFromAnotherPage()
{
    $("#fromAnotherPage").load("add.html");
}

I want to load the contents of add.html into a variable, then do somethign with it later, but when I declare a variable, I can't use .load on it.

      var x= "";
      x.load("add.html");
0
Comment
Question by:jackjohnson44
[X]
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
2 Comments
 
LVL 5

Accepted Solution

by:
cdaugustin earned 2000 total points
ID: 24392583
hi,

please read at

http://docs.jquery.com/Ajax/load

you probably want to use

http://docs.jquery.com/Ajax/jQuery.ajax

(look at both options and examples and you should be fine). If not let us know il point the way even further.
0
 

Author Comment

by:jackjohnson44
ID: 24398258
Thanks.
I already got load working from that example on the jQuery site.

The example they give replace the contents of something in a selector with the contents from another page.  I am looking to get the contents of a page into a variable, then maybe  append it later.

So instead of:
$("#fromAnotherPage").load("add.html");

I want to:
  var x= "";
      x.load("add.html");
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

688 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