rinserepeat
rinserepeat

Reputation: 165

Why cant i access variable in jquery function

I'm wondering why I can't access the value of variable ("dial") any help would be great.

<input type="text" class="dial" value="50" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://raw.githubusercontent.com/aterrien/jQuery-Knob/master/dist/jquery.knob.min.js"></script>
<script type="text/javascript">
    $(function() {
                    var dial = $(".dial");
                    
                    function onDialChange(){
                        console.log(dial.value); // for some probably obvious reason I can't access this value.
                    }
                    
                    dial.knob({
                        'release':function(){},
                        'change':onDialChange,
                        'draw':function(){},
                    });
                                 

                });
</script>

Upvotes: 0

Views: 50

Answers (2)

ozil
ozil

Reputation: 7117

function onDialChange(){
    console.log(dial.val()); //for value
    console.log(dial.text());  //for text
}

Upvotes: 3

Brijesh Bhatt
Brijesh Bhatt

Reputation: 3830

.val() is the proper function in jquery to return value of input element.

console.log(dial.val());

For your Reference

Upvotes: 3

Related Questions