Syntax for object with multiple elements
Hello,
I'm quite new to jquery and i would like to know the best syntax to create an object with couple of DOM elements.
I mean something like this:
- $('<div/>').append(newBlock());
- /////
- function newBlock()
- {
- var $block =$( $('<h1/>')
- .text('Title'), //????
- $('<h2/>')
- .text('subTitle'));
- return $block;
- }
I know this synthax isnt correct, but thats give you the idea of what i mean.
I can get it work like this but its really weird:
- $('<div/>').append(newBlock());
- /////
- function newBlock()
- {
- var h1 = $('<h1/>')
- .text('Title');
- var h2 = $('<h2/>')
- .text('subTitle');
- return $("<div>").append(h1.clone()).html()+$("<div>").append(h2.clone()).html();
- }
Could someone point me to the right direction, thx!