0

Hi I have a div that I want to change some values in, when I click a button.

If I click on

<button id="image320x150">320 x 150</button>

then I want to change the width to 100 and the height value to 200 in the div.

and if I click on:

<button id="image320x200">320 x 200</button>

then I want to change the width to 50 and the height value to 100 in the div.

<div style="width:200px;height:287.5px;overflow:hidden;">

And I want the div to have the original values at first. Thanks a lot!

1
  • 5
    .....what? The values in the buttons and the values in your buttons have no correlation, unless I'm missing something... Commented Nov 3, 2010 at 12:05

4 Answers 4

1

something like:

$('#try-me').click(function() {
    $('#aDiv').css({width: '30px', height: '20px'})
})

example: http://jsfiddle.net/UDvPR/

Sign up to request clarification or add additional context in comments.

Comments

0
<script>
  $("#something").click(function () {
    $(#something2).css("width","100");
  });
</script>

http://api.jquery.com/css/

Comments

0

I don't really got the logic but whatever.

<script type="text/javascript">
var sizes = [{width:100,height:200},{width:50,height:100}];
function setSize(i){ $("#target").css(sizes[i]); }
</script>
<button id="image320x150" onclick="setSize(0);">320 x 150</button>
<button id="image320x200" onclick="setSize(1);">320 x 200</button>
<div id="target" style="width:200px;height:287.5px;overflow:hidden;"></div>

7 Comments

Anpher, great thanks a lot it works as it should! But now another problem showed up, I need at the same time change the values here to the ones in sizes: var rx = 200 / coords.w; var ry = 287.5 / coords.h;
@Claes Gustavsson You need to change values where?
In two variable thats called rx and ry thats in another function. var rx= 200/coords.w; and var ry=287.5/coords.h;
@Claes Gustavsson still nothing. var rx= 200/coords.w; and var ry=287.5/coords.h; <- variables defined. what else do you need?
When I click on eg the button id="image320x150" above I want to set the values in the variables aswell, something like $('#image320x150').click(function() { $('var rx').("50"); $('var ry').("100"); });
|
0
Jquery(document).ready(function() {

     jquery('#image320x150').click(function(){
         jquery('#div_id').css("width","100");
         jquery('#div_id').css("height","200");

      });

     jquery('#image320x200').click(function() {
         jquery('#div_id').css("width","50");
         jquery('#div_id').css("height","100");

      });
});

3 Comments

if your using jquery... keep it in the (document).ready... function... its bad practice to not use it.
JavaScript is case sensitive, you need to use jQuery, not a variant of it, as they won't be defined.
its an example. in most cases $ is going to be used anyway, or if its being done in an editor intelisense will take care of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.