0

I'm working on the following page: http://mockingbirdagency.com/thebox/bettercss/login-1.html I know very little Javascript so please dumb it down for me.

I would like "Register with your email address" to be centered on the block and to go at the top of it (by deleting margin-top: 30px;) when clicked on (the idea being not to have such a big block).

How can I add this to the JS function ??

Thanks!

1
  • could you add some mark up please. Commented Dec 20, 2012 at 11:17

3 Answers 3

2

In your jquery click handler

$(document).ready(function() {
    $('h1').click(function() {
        $('#details').toggle(500);
    });
});

you need to add

$(this).css("margin-top","");

the final code:

$(document).ready(function() {
    $('h1').click(function() {
        $(this).css("margin-top","");
        $('#details').toggle(500);
    });
});
Sign up to request clarification or add additional context in comments.

Comments

2

You may want to use jquery for this so as a basic guide:

$("#target").click(function() {
  alert("Handler for .click() called.");
});

So when you click the item with an ID of target this would show an alert box saying: "Handler for .click() called."

So now you want to add a style to that item you clicked

$("#target").click(function() {
      $(this).css("margin-top","0");
    });

So, now you hit the item, it runs and adds the CSS of margin-top:0; to 'this' which is the item triggering the event.

Obviously you will need to change #target to the ID of the item you want the event to trigger on, you can also use .target and apply to an item with only a class.

Find out more at http://jquery.com

Comments

-1

Try this one:

$("#hh").click(function(){
    $(this).css("margin-top","0px");
});

Comments

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.