Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-14
2
Medium Priority
?
899 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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)

972 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