a3rxander
a3rxander

Reputation: 906

.change() .css width

I wanna change the width of a css when the value of a text to change on value.

Javascript:

<script>
 $("inpu").change( function() {
 $(#calidad).css({
  width: function(index, value) {
    return parseFloat(value) * 1.2;
  }, 
  });
  });
</script>

CSS :

#calidad{ width: 20px; height: 15px; background-color: #f33; }

html:

<input type="text" id="inpu" name="inpu" value="2">
<div id="calidad"></div>

Upvotes: 0

Views: 482

Answers (2)

matchew
matchew

Reputation: 19645

I may not understand the question, but do you want to change the width to the val of the input?

here is an example using px (you could use em, points, etc)

$(function() {   
 $("#inpu").change( function() {
        $('#calidad').css({
              width: getWidth});    
        });
});

    function getWidth() {
     return $('#inpu').val()  + 'px' 
    }

here is a live example using a forked version of Steve's fiddle: http://jsfiddle.net/pK2qR/

Upvotes: 0

Steve Wellens
Steve Wellens

Reputation: 20620

I fixed your code and made a jsFiddle:

http://jsfiddle.net/xWXWD/

Both selectors were incorrect.

Upvotes: 2

Related Questions