0

I have the below code, the principle being that when clicking on the < td > it gives two alert boxes:

1)with the data-value (e.g. 1)

2) with the text (11001)

but when I click on it I get the follwoing error for the 'type' variable:

function ( value ) {
        return jQuery.access( this, function( value ) {
            return value === undefined ?
                jQuery.text( this ) :
                this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
        }, null, value, arguments.length );
    }

I'm assuming it is something quite obvious, but I can't see what???

<html>
<head>
    <script language="JavaScript" src="../Generic/JAVASCRIPT/jquery.js" type="text/javascript"></script>
    <script>
        $(document).ready( function() 
        {
            $('.updatefield').click(function() 
                { 
                    var typeid = $(this).closest('tr').children('td.rowType1').data('value');
                    var type = $(this).closest('tr').children('td.rowType1').text;

                    console.log(typeid);
                    console.log(type);
                }
            )
        })  
    </script>
</head>


<body>
<Table>
    <tr>
        <td class="updatefield rowType1" data-value="1">11001</td>
    </tr>
</Table>
</body>
</html>

2 Answers 2

1

A typo here:

var type = $(this).closest('tr').children('td.rowType1').text();

instead

var type = $(this).closest('tr').children('td.rowType1').text;

.text() is method not a property.. :)

Fiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

1

text() is a method not a property. Thus, you're referencing rather than calling the function.

Change it to: var type = $(this).closest('tr').children('td.rowType1').text();

1 Comment

thanks for the response, I can't believe I missed that (it was late Friday - that's my excuse). cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.