How i can replace the width in below code with a variable value?
$('<div/>', {
'class': "formErrorContent",
width: '13px',
text: promptText
}).appendTo(prompt);
Like
var promptWidth = (promptText.length * 5) - (promptText.length/2);
var promtWidthString = promptWidth + 'px;'
var promptContent = $('<div/>', { 'class': "formErrorContent", style: 'width:' + promtWidthString , text: promptText}).appendTo(prompt);
The above code will end up in a extra
< /br >
at end of the promtText
As you are using
appendTothere is no need to store the object in a variable. you can usewidthfor settingwidthstyle to the element, also remove the+from your code, note that if you are adding markup, instead of text, you should usehtml.