Toggle amount of rows in text area.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//short version, the one in the answer | |
$('thebutton').click(function(){ | |
$('thetextarea').attr('rows', $('thetextarea').attr('rows')==1?5:1); | |
}); | |
//short version, just using selectors once | |
$('thebutton').click(function(){ | |
var $textArea = $('thetextarea'); //declare a variable to avoid using the same jQuery selector twice. | |
$textArea.attr('rows', $textArea.attr('rows')==1?5:1); | |
}); | |
//long version | |
$('thebutton').click(function(){ | |
var currentRows = $('thetextarea').attr('rows'); //obtain the current number of rows in the textarea | |
var newRows; //declare a variable to hold the new number of rows | |
if(rows == 1){ //if just one... | |
newRows = 5; // it should become 5 | |
}else{ | |
newRows = 1; //else, (not 1), become 1 | |
} | |
$('thetextarea').attr('rows', newRows); //assign the new value to the rows attribute of the textarea | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment