0

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

Community
  • 1
  • 1
aWebDeveloper
  • 33,798
  • 37
  • 161
  • 232

2 Answers2

1

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

Nicola Peluchetti
  • 74,514
  • 30
  • 136
  • 188
  • which is exactly the same as explained in the link @Web Developer referenced in his question. – Juri Dec 21 '11 at 12:22
  • @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 – Nicola Peluchetti Dec 21 '11 at 12:27
0

see example here

Community
  • 1
  • 1
Rohan Kumar
  • 39,838
  • 11
  • 73
  • 103