Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#6286 closed bug (worksforme)

Unexpected call to method or property access.

Reported by: nata79 Owned by:
Priority: undecided Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: Unexpected call to method or property access Cc:
Blocked by: Blocking:

Description

By using "$(elId).text(myTextValue);" to set element text value, regardless ver1.3.2 or ver1.4.2, the exception "Unexpected call to method or property access" will throw by Internet Explorer 7/8.

The exception is throw at line "this.appendChild( elem );".

### CODE ### text: function( text ) {

... ... if ( typeof text !== "object" && text !== undefined ) {

return this.empty().append( (this[0] && this[0].ownerDocument
document).createTextNode( text ) );

} ...

},

append: function() {

return this.domManip(arguments, true, function( elem ) { if ( this.nodeType === 1 ) {

this.appendChild( elem );

}

}); },

Change History (15)

comment:1 Changed 13 years ago by jerone

I had this problem too, and I solved it with adding an HTML5 enabling script:

<!--[if lt IE 9]>
<script>
  var e = ("abbr,article,aside,audio,canvas,datalist,details," +
    "figure,footer,header,hgroup,mark,menu,meter,nav,output," +
    "progress,section,time,video").split(',');
  for (var i = 0; i < e.length; i++) {
    document.createElement(e[i]);
  }
</script>
<![endif]-->

comment:2 Changed 13 years ago by addyosmani

Priority: undecided
Resolution: worksforme
Status: newclosed

This is working fine for me. If you would like to submit additional test cases or further details to assist is in re-evaluating the original bug submitted we would be more than happy to take another look at it.

comment:3 Changed 12 years ago by anonymous

This too does not work...!!! JQUERY 1.3.2 min. The same old error.. of IE 7 & 8 ... "Unexpected call to method or property access."...

function getPeople(people) {

$("#people_list").text(""); UL element ID $("input#autoNames").text(""); $.each(people, function(i) {

$("#people_list").append("<li>" + this.Name + "</li>");

});

}

Problem statement: {this.appendChild(E)}

comment:4 Changed 12 years ago by jitter

Your comment is rather unclear to me. If you could so kind to provide a reproducible minimal test case which shows this bug with the current jQuery version we will investigate this issue.


How to report bugs

comment:5 Changed 12 years ago by anonymous

HTML:

<input type="text" id="autoNames" />

<label id="lblSelName"> </label> <p>

<input type="button" id="addPerson" value="Add Person" />

<input type="button" id="deletCustomer" value="Delete Person" />

<input type="button" id="getPeople" value="Refresh List" />

<br />

<ul id="people_list"> </ul>

</p>

Script:

<script type="text/javascript">

$(this).ready(function() {

$.getJSON("/Home/PeopleGet", null, autoTextBox);

});

$(this).ready(function() {

$.getJSON("/Home/PeopleGet", null, getPeople);

});

function autoTextBox(people) {

var myCars = new Array(); $.each(people, function(i) {

myCars[i] = this.Name;

}); $("input#autoNames").autocomplete({

source: myCars

});

}

$(function() {

$("#getPeople").click(function() {

$.getJSON("/Home/PeopleGet", null, getPeople);

});

});

function getPeople(people) {

$("#people_list").text(""); $("input#autoNames").text(""); $.each(people, function(i) {

$("#people_list").append("<li>" + this.Name + "</li>");

}); $("input#autoNames").val();

}

$("#addPerson").click(function() {

var name = $("input#autoNames")[0].value; if (name == "") {

alert("You must provide a name"); return;

} var person = { Name: name }; $.post("/Home/PeopleSave", person, null, "json"); $.getJSON("/Home/PeopleGet", null, getPeople); alert("Customer is added to the database!"); $("input#autoNames").val(); $("input#autoNames").focus();

});

$("#deletCustomer").click(function() {

var name = $("input#autoNames")[0].value; if (name == "") {

alert("You must provide a name"); return;

} var person = { Name: name }; $.post("/Home/PeopleDelete", person, null, "json"); $.getJSON("/Home/PeopleGet", null, getPeople); alert("Customer successfully deleted from the database..!"); $("input#autoNames").val(); $("input#autoNames").focus();

});

</script>

comment:6 Changed 12 years ago by email@…

Bug still exists in 1.5.2;

or var $menu = $input.after('<ul></ul>'); var $menu = $input.after('<ul />');

$menu.append("<li>item</li>");

IE 80.0.6001 on Win XP

comment:7 Changed 12 years ago by david.m.mahon@…

I experienced the issue as well. The error was thrown when, somehow, in the context of append(), this referenced a SCRIPT tag and elem referenced a DIV.

I resolved the issue by rewriting append() to: return this.domManip(arguments, true, function( elem ) { if ( this.nodeType === 1 ) {

if (this.tagName.toUpperCase() === "SCRIPT") {

elem.appendChild( this );

} else {

this.appendChild( elem );

}

} });

comment:8 Changed 12 years ago by anonymous

A simple jsfiddle, does not work with IE 8 no matter what version of jquery I use: http://jsfiddle.net/4XZRT/

comment:9 in reply to:  8 Changed 12 years ago by anonymous

Replying to anonymous:

A simple jsfiddle, does not work with IE 8 no matter what version of jquery I use: http://jsfiddle.net/4XZRT/

Bad formed <a> tag, fix it and it works

comment:10 Changed 11 years ago by anonymous

I have got the same error. I replaced .html with .replaceWith and it worked.

comment:11 Changed 11 years ago by KendallB

Also getting the same error.

comment:12 Changed 10 years ago by anonymous

i also had the same error in jquery-1.9.1 the problem was i used $('#elid').text();

i replaced text with val and it worked for me :)

comment:13 in reply to:  1 Changed 10 years ago by anonymous

Replying to jerone:

I had this problem too, and I solved it with adding an HTML5 enabling script:

<!--[if lt IE 9]>
<script>
  var e = ("abbr,article,aside,audio,canvas,datalist,details," +
    "figure,footer,header,hgroup,mark,menu,meter,nav,output," +
    "progress,section,time,video").split(',');
  for (var i = 0; i < e.length; i++) {
    document.createElement(e[i]);
  }
</script>
<![endif]-->

comment:14 Changed 10 years ago by anonymous

This can happen in IE8 when using a class as a selector.

Imagine the following...

<p class="update_me">Some text</p> <input class="update_me" type="text" name="something" value="123">

If you were to do the following in IE8 it would cause this error...

$('.update_me').text('456');

Other browsers will let you get away with it, but IE8 will complain as the input field isn't compatible with the .text() method.

comment:15 Changed 10 years ago by matzipan

Happened to me, as well, while using .text("blabla") on an input.

Note: See TracTickets for help on using tickets.