Suggest a better way to do the following in jquery . also give me the native js code to do it
$('<div id="dialog-confirm" title="'+confirmbox.title+'"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>'+confirmbox.message+'</p></div>')
.appendTo('body');
Why the need. look at "Idiomatic Syntax for Creating Elements" section of this link https://stackoverflow.com/tags/jquery/info
asked Dec 21, 2011 at 12:16
-
2seeing as how you asked so nicely :/Alex– Alex2011年12月21日 12:19:50 +00:00Commented Dec 21, 2011 at 12:19
-
stackoverflow.com/questions/327047/…Sudhir Bastakoti– Sudhir Bastakoti2011年12月21日 12:19:56 +00:00Commented Dec 21, 2011 at 12:19
2 Answers 2
youc colud create the elements in this way:
var div $('<div>', { id: "dialog-confirm", title: confirmbox.title});
var p = $('<p>');
p.text(confirmbox.message);
var span = $('<span>').addClass('ui-icon ui-icon-alert').css({ float: "left", margin: "0 7px 20px 0"});
p.prepend(span);
div.append(p);
and then append them as needed
answered Dec 21, 2011 at 12:19
2 Comments
Juri
which is exactly the same as explained in the link @Web Developer referenced in his question.
Nicola Peluchetti
@Juri i thought he wanted the code to do what was written in the article since his code is different from the code found in the article
see example here
answered Dec 21, 2011 at 12:19
Comments
lang-js