HTML Tittle attribute showing only First Word

Viewed 1533

I using title attribute in jQuery.

createAlert: function () {            
  return '<img id="img" class="img pull-left" src="/Content/img/demo_16px.png" tabindex="0" style="outline: none;" title=' + demo.rawData + '></span>';
}

Here In this code, title contain dynamic data(demo.rawData Contain text = 'This is my code')

But when I hover in a browser for title it only displaying This(i.e only first word)

Can anyone tell what I am doing wrong.?

2 Answers

You need to surround the title in "" like so title="' + demo.rawData + '" rather than title=' + demo.rawData + ' otherwise the rendered HTML will be invalid

createAlert: function () {            
  return '<img id="img" class="img pull-left" src="/Content/img/demo_16px.png" tabindex="0" style="outline: none;" title="' + demo.rawData + '"></span>';
}
Related