Creating div element using jquery and adding inner html

html, jquery

Solution

You can also do something like this:

js

$("<div/>",{
    id: "a",
    text:"sadsad",
    style:"background-color:red;height:50px;",
    class: "classA"
  }).appendTo("body");

fiddle

Problem

Im making some div element dynamically ``` var QuickPanelItem = $('<div/>', { 'id': 'div' + WidgetDetails.Name + 'QuickPanel', 'class': 'left_slidethumbs button_' + WidgetDetails.Name + '' }); QuickPanelItem.append($('<div/>', { 'class': 'text_button' })); $("#divLeftQuickPanel").append(QuickPanelItem); ``` my doubt is ``` $('<div/>', { 'class': 'text_button' }) ``` we can add attributes of the element by writting them in the flower brackets as in the above line, But how can we add background-image,margin,padding etc which comes under style property. Also adding inner html.

Original source