Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2012, 09:13 PM   PM User | #1
aaronhockey_09
Regular Coder

 
Join Date: Dec 2010
Posts: 411
Thanks: 21
Thanked 55 Times in 55 Posts
aaronhockey_09 is an unknown quantity at this point
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

Code:
<div class="comment-section">
<div class="comment"><p>This is where text would go. </p></div>
<div class="read-more">Read More</div>
</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

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

    }
  });
</script>
aaronhockey_09 is offline   Reply With Quote
Old 04-25-2012, 10:19 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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
Code:
$('.comment')
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..
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
change, div, height, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:59 AM.


Advertisement
Log in to turn off these ads.