Pass id selector content to a variable?

Can I pass the content of an id selector to a variable?
I am using a jQuery plugin which passes some data to an id selector (‘#alt-text’). If I create a div tag with that id, the content for (‘#alt-text’) gets displayed in the div tag- everything fine. However, I need to split the selector (or parse the selector) to the assign different sections of the data to differnt div tags.

can’t seem to get this started. If I try:
var xxx = $(‘#alt-text’);
$(‘#otherDivTag’).html(xxx);

it does not work. My desire is to do something like:
var xxx = $(‘#alt-text’);
$(‘#otherDivTag’).html(xxx).text().split(’ ')[0];

Any suggestions?
-Greg

I’m not 100% clear on what you’re trying to do, but to start with, the html() function doesn’t take an object as a parameter, it takes a string. So instead of doing this:


var xxx = $('#alt-text');
$('#otherDivTag').html(xxx);

You need to do this:


var xxx = $('#alt-text');
$('#otherDivTag').html(xxx.html());

So now you’re passing it the HTML string contained within the div represented by xxx rather than the jQuery object itself.

That helps. Think you’re right in that I need to get my objects and strings straight.
I am using cloud-carousel on my webpage for a slideshow. The carousel takes the ‘alt’ attribute from the slideshow image and passes it to the page for a description. I can put any div ‘id’ name I want in that parameter and the alt data will pass through fine. I don’t know carousel code well enough to pass data separately from the carousel code itself.
I have 3-4 different pieces of data (firstname, date, description, city, etc.) that I want to pass to different div tags on my page to better describe the slideshow pic being viewed. I am doing this by loading up the alt attribute of the original image with some php array data; neatly delimited.
<img …alt=“<?php echo $ph01[1][0] . “|-|” . $ph01[2][0]… ;?>” … />
I can run the code and get all the pieces of data in the one div tag to show up. But I am not having any luck with a .split() or other means to separate the data into separate variables/objects based on my delimiters which could then be inserted into other divs.

I need to take the content of the $(‘#alt-text’) div and manipulate it as a string. Then, take the resulting array data and put that back into different div tags on the page as appropriate. (Ideally, the $(‘#alt-text’) would be a variable to start with and I could then work on it directly but I don’t know how to get that…)

I should have started with this detail, sorry. The crux of my problem is not being able to get and manipulate the contents of the $(‘#alt-text’) to begin with.

Once I can get it to a var I can work on it like this:
var xxx = ???;
/* split up alt attribute string to get the caption data */
var getDet = xxx.split(“|-|”);
var descDetail = getDet[0];
var dateDetail = getDet[1];
var fnameDetail = getDet[2];
$(‘.captionDesc’).html(descDetail);
$(‘.captionDate’).html(dateDetail );
$(‘.captionFname’).html(fnameDetail);

-Greg

Given that code at the end, I would think that setting xxx equal to $(“#alt-text”).html() would do the trick…unless the slideshow code for some reason is surrounding the text with extra HTML, in which case $(“#alt-text”).text() would work better.