1

I'm developing a plugin for Spiceworks that reformats a block of text. Unfortunately it only works in Firefox, and not in Chrome or IE.

plugin.includeStyles();
function log(msg) {
  throw new Error(msg);
}
SPICEWORKS.app.helpdesk.ticket.ready(function(){
  console.log('###Start function###');
  console.log('###URL###');
  var url = jQuery("li.custom")[2].lastElementChild.firstChild.wholeText;

  //Check to see if category is project.
  for(var i=0;i<jQuery("li.custom").length;i++)
  {
    if (jQuery("li.custom")[i].lastElementChild.firstChild.wholeText == "Project")
    {
        for(var u=0;u<jQuery("li.custom").length;u++)
        {
          if (jQuery("li.custom")[u].lastElementChild.firstChild.wholeText.contains("http"))
          {
            jQuery("li.custom")[u].innerHTML = '<a href="'+url+'" target="_blank"><span class="projectLink">Project Link</span></a>';
          }
       }
    }
  }
});​

Chrome is showing that there's an error "Uncaught TypeError: Cannot read property 'lastElementChild' of undefined" on line 9 (var url = ...) Here's a screenshot comparing the display of the different browsers.

What can I do to make the display consistent across the different browsers?

  • It sounds like you have a different number of `li` elements in Firefox versus IE and Chrome, since `jQuery("li.custom")[2]` is undefined in those browsers, but apparently not in Firefox. Can you check `jQuery("li.custom").length` in all your browsers, just before the problematic line? – apsillers Jan 29 '13 at 14:33
  • Just checked jQuery("li.custom").length, and it resolves to 3 in all browsers. – Nick Graham Jan 29 '13 at 14:51
  • Just solved my own problem. For some reason `lastElementChild.firstChild.wholeText` is null under IE&Chrome, but if I change it to `lastElementChild.innerHTML` then it all works fine under every browser. I also had to change `lastElementChild.firstChild.wholeText.contains("http")` to `lastElementChild.innerHTML.indexOf("http") !== -1` in order to make it work properly. – Nick Graham Jan 29 '13 at 15:27

0 Answers0