1

I want to display the title attribute normally. The tittle attribute has displayed in code now. How to change it from text to html?

Image

I have tried some code below but not work. Please help!

    function TextToHTML(NodeSet, HTMLregexp) {
      var CellContent = "";
      var i=0;
      while (i < NodeSet.length)
      {
        try 
        {
          CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
          if (HTMLregexp.test(CellContent)) 
          { NodeSet[i].innerHTML = CellContent; }
        } 
        catch(err)
        {}

      i=i+1;
      }
    }
setInterval(
function(){
   var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
   TextToHTML(document.getElementsByTagName("a"),regexpA);

   var regexpDIV = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
   TextToHTML(document.getElementsByTagName("div"),regexpDIV);

   var divs = document.querySelectorAll('div.ms-acal-item');
   var regexpTITLE = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
   for(var i=0; i<divs.length; i++){

      divs[i].getAttribute("title").replace(/<(?:.|\n)*?>/gm, '');
      TextToHTML(divs[i].getAttribute("title"),regexpTITLE);
   }

}, 10);
SAUMYA
  • 1,508
  • 1
  • 13
  • 20
  • title attribute does not support HTMl tags. it has to be text. You can create popup/tooltip on mouseover either using jqueryUI or of your own if you want to use html format. – rajesh Jan 23 '17 at 06:39
  • check This thread..[Extract the text out of HTML string using JavaScript](http://stackoverflow.com/questions/28899298/extract-the-text-out-of-html-string-using-javascript) – Abhishek Chandel Jan 23 '17 at 06:40
  • Thx Abhishek chandel! I have solved by myself. – user1735815 Jan 23 '17 at 07:43

1 Answers1

0

The issue has solved:

var divs = document.querySelectorAll('div.ms-acal-item');
var regexpTITLE = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
for(var i=0; i<divs.length; i++){

  divs[i].getAttribute("title").replace(/<(?:.|\n)*?>/gm, '');
  TextToHTML(divs[i].getAttribute("title"),regexpTITLE);
}

Change the above code like the following:

var divs = document.querySelectorAll('div.ms-acal-item');
for(var i=0; i<divs.length; i++){       
    var titleOriginal = divs[i].getAttribute("title");      
    var newTitle = titleOriginal.replace(/<(?:.|\s)*?>/g, "");

    titleOriginal = divs[i].setAttribute('title', newTitle);
}
  • You could reduce the code within your loop to one line: `divs[i].setAttribute('title',divs[i].getAttribute("title").replace(/<(?:.|\s)*?>/g, ""));` – Thriggle Jan 23 '17 at 16:18