SCRIPT16385: Not Implemented

The following code works fine in Chrome and FireFox, but it doesn't work as expected in IE:

if (jQuery.trim(jQuery("#"+element_id.name).val()) != "" && jQuery.trim(jQuery("#"+element_id.name).val()) != "0") {
  jQuery("#filters-box").append('<span id="filter-'+ element_id.name +'" class="toggler"><button class="button white" onClick="removeFilter(\'filter-' + element_id.name + '\')"> βœ– </button>' + document.getElementById(element_id.name + "_caption" ).value + ' -> ' + document.getElementById(element_id.name).value + '</span>');
}

      

Although he can add HTML code and display it correctly on the page, his onClick event generates the above error message.

+3


source to share


3 answers


Strange I tried changing the name of your "removeFilter" function and it works fine.



var element_id = {
  name: "test",
  "test_caption": "_caption"
};

function rmvFilter(ele) {

  alert(ele);
}

var html = '<span id="filter-' + element_id.name + '" class="toggler">';
html += '<button class="button white" id="button" onClick="rmvFilter(\'caption_' + element_id.name + '\');"> βœ– </button></span>';
jQuery("#filters-box").append(html);
      

Run codeHide result


I find no errors in your code, except that the exact combination of the name does not work strangely only in IE9

+4


source


If you're precompiling the string with jQuery, you can attach events as if they were already in the DOM (mostly). This is cleaner, non-intrusive, and should work in all browsers that jQuery supports:



if (jQuery.trim(jQuery("#"+element_id.name).val()) 
    != "" && jQuery.trim(jQuery("#"+element_id.name).val()) != "0") {

    // precompile to a temp var
    var $temp = jQuery('<span id="filter-'+ element_id.name +'" class="toggler"><button class="button white"> βœ– </button>' + document.getElementById(element_id.name + "_caption" ).value + ' -> ' + document.getElementById(element_id.name).value + '</span>');

    // this works fine
    $temp.find('button.button.white').on('click', function () { removeFilter('filter-' + element_id.name); });

    jQuery("#filters-box").append($temp);
}

      

+1


source


Thank you, Karteek. I just ran into the same problem as the "removeFilter (event)" function in IE9 (it worked fine in Firefox and Chrome) and changing the function name worked for me too.

I can only assume it was some built-in feature for IE that hasn't been implemented since IE9, so the browser is calling the wrong function that throws a not executed error.

0


source







All Articles