Solved

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

Posted on 2009-05-14
2
889 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now