Solved

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

Posted on 2009-05-14
2
890 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
2 Comments
 
LVL 5

Accepted Solution

by:
cdaugustin earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
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 invoke it on a web page. 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.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now