Id:Nome:1515Thiago<...">

Each returns "undefined"

Guy van

I have a table like

<table id="table4"> <tr> <td>Id:</td> <td>Nome:</td> </tr> <tr> <td>1515</td> <td>Thiago</td> </tr> <tr> <td>2015</td> <td>Guttierre</td> </tr> </table> 

and when my script does ...

  $("#table4 tr td:nth-child(1)").each(function ai() { var d = $(this).text(); if ((d != 0) && (d != "") && (d != 'undefined') && (d != "Id:")) { alert(d); }; }); 

It returns: 1515, then 2015 and then returns an error:

Microsoft JScript runtime error: "Undefined" is null or not an object.

Why does it return "Undefined" ???

Black guys!

+4
source share
2 answers

Named function literals are legal JavaScript, but I find it due to scope issues that some browsers might not handle properly. From the link that Marko Dumic provided in her comment:

Unfortunately, JScript (i.e. the implementation of ECMAScript in Internet Explorer) has seriously confused named functional expressions.

If you are not going to use the ai function elsewhere, try deleting the name (oh and, as Orbling says, undefined is a variable if you compare it with this value, so remove the quotes):

 $("#table4 tr td:nth-child(1)").each(function() { var d = $(this).text(); if ((d != 0) && (d != "") && (d != undefined) && (d != "Id:")) { alert(d); }; }); 
+4
source

I am checking your script for chrome. Everything works well. Remember to wrap this feature in

 $(document).ready() 

or put it in the body section.

+1
source

Source: https://habr.com/ru/post/1333568/


All Articles