user1906005
user1906005

Reputation: 85

What is wrong with the syntax in this?

<script type="text/javascript">
                $(document).ready(function() {
            $('#Catid').change(function(){
                var optvalue = $(this).val(),
                div = $('#' + 'parentid' + optvalue);
                $('div').hide();
                div.show();
            });
        });​ 
              </script>

Im getting a console error but I have no idea why

Upvotes: 0

Views: 207

Answers (2)

nolabel
nolabel

Reputation: 1157

You've asked "What is wrong with the syntax in this", so I figured I should point this one out too.

The problem is with this code here:

div = $('#' + 'parentid' + optvalue);

The div is a global variables and it is consider bad practice.

A better way to rewrite this is to include this as part of the initial var.

var optvalue = $(this).val(),
    div      = $('#' + 'parentid' + optvalue);

Upvotes: 2

David G
David G

Reputation: 6871

Looks like you have an issue with the last line. Theres a hidden character right at the end there. Delete it and write it again, that should sort it!

Upvotes: 4

Related Questions