Solved

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

Posted on 2009-05-14
2
897 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

626 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