1

Hi i want to add a few hidden divs to an array and show them afterwards in different places one by one. I am a rookie so i will really appreciate your patience. http://jsfiddle.net/alexnode/qSZx6/1/

i have three divs like

<div id='a'><p>Aorum</p>Lorem ipsum dolor sit amet</div> 
<div id='b'><p>Borum</p>Lorem ipsum dolor sit amet</div> 
<div id='c'><p>Corum</p>Lorem ipsum dolor sit amet</div> 

and i create an array

var myarray = new Array();
myarray[0] = $( '#a' ).html();
myarray[1] = $( '#b' ).html();
myarray[2] = $( '#c' ).html();

my problem is that when i call

$('<div/>', {
                class: "someclass",
                html: myarray[0],

            } ).appendTo('body');

I get all the divs printed. I am sure it is something very basic but what ?

Edit : What i want is to get myarray[0] to include only the html of the div id=a not all the divs as you can see in the fiddle.

4
  • 1
    div#a is never closed Commented Jun 7, 2013 at 18:09
  • 1
    change all the closing <div> to </div> Commented Jun 7, 2013 at 18:10
  • ooops that is not the problem though in the fiddle. Commented Jun 7, 2013 at 18:13
  • completely idiotic there was an open div in the fiddle! Commented Jun 7, 2013 at 19:52

2 Answers 2

2
var divs = $('#a, #b, #c');

$('<div/>', {class: "someclass"}).append(divs);
Sign up to request clarification or add additional context in comments.

4 Comments

have a look at the fiddle i append the class my problem is that i get all the parsed divs printed
I guess you are trying to toggle between two sections when the menu items are clicked. but what you explained in your question is completely different from the fiddle. Anyway, see the fiddle where I did that jsfiddle.net/qSZx6/16
Sorry and thank you, I didn't describe my problem properly, my problem is that when we get the div to the array and then append them i get all the array text (english,german etc )while i want to get only the html text of only one div id. I just want to have the <div id="german"></div> or the <div id="english"></div>. The console log is great by the way thank you
I had a div open!! this is why i did get all the divs ! Idiotic i mark your answer as correct since you helped me a lot with the window toggle!
0

You don't really need to store the "html" into the divs. You can store the DOM element. The jQuery Object itself is an array-like object that stores them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.