Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Thanked 59 Times in 59 Posts

    Thumbs down Change height of Div using Javascript

    Hey guys, so i have a comment section.
    And what i want to do is if the height of the comment box is larger then lets say 100px.
    I want to set the height of the comment box to 50px and then display a "read more" button.

    And this read more button would toggle and allow the height to be "auto" and not set to 50px.

    so my html would look like this

    <div class="comment-section">
    <div class="comment"><p>This is where text would go. </p></div>
    <div class="read-more">Read More</div>
    I have the class "read-more" set to "display:none"

    How would i do this?

    This is what i have / was trying and have been unsuccessful

    <script type="text/javascript">
      $(function(if ($".comment".style.height > 100px;){
          $".comment".style.height = 50px;
    	  $".read-more".style.display = block; 

  2. #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 570 Times in 563 Posts
    If this is really your code ... you should learn about jQuery syntax

    $() is the jQuery function used for (almost) everything in jQuery. And everything else is parameters or (chainable) methods to this function.

    So if you want to select with a class selector, you'll have to do
    On top of this, .style is NOT a jQuery method and can therefore not be used on a jQuery object.

    Maybe it's not jQuery you are using? But what else could it be?

    EDIT: Ok, there are even more things that I did not see before. Like using string literals as if they were variables. All of this makes me guess that this is your very first attempt on Javascript. Better start with some Javascript basics first and increase your knowledge step by step ...
    Last edited by devnull69; 04-25-2012 at 10:26 PM.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts