最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML Tittle attribute showing only First Word - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

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>';
}

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

发布评论

评论列表(0)

  1. 暂无评论