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.?
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.?
Share Improve this question edited Nov 10, 2017 at 5:20 Shiladitya 12.2k17 gold badges28 silver badges42 bronze badges asked Nov 10, 2017 at 5:14 SanjivSanjiv 1,2982 gold badges13 silver badges31 bronze badges 1- Add quotes around your attribute value. – John Ellmore Commented Nov 10, 2017 at 5:15
2 Answers
Reset to default 5You 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>';
}
Here you go with one more solution using ES6 template literal
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>`;
}
Reference Document: https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Template_literals