Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As I am new to javascript:

I would like to change onmouseover one div id with another div id. On mouse out everything would go back. I was looking and tried this online for several hours with no luck.

Trying this:

    <script>

$('.one').hover(

function() {

$('.two').attr('id', 'header-email'); //box two's ID becomes box one
$(this).attr('id', 'header-email2'); //box one's ID becomes box two
}, function() {

$('.two').attr('id', 'header-email2'); 
$(this).attr('id', 'header-email');

}); //end hover one

$('.two').hover(

function() {

$('.one').attr('id', 'header-email2'); //box two's ID becomes box one
$(this).attr('id', 'header-email'); //box one's ID becomes box two

}, function() {

$('.one').attr('id', 'header-email');
$(this).attr('id', 'header-email2');

 }); //end hover one

</script>

my html:

 <div id="header-email"  class="one" style="visibility: visible;">textinhere<a href="mailto:tips@email.net">tips@email.net</a></div>
        <div id="header-email2" class="two" style="visibility:hidden;">textinhere<span><br>sometext</span></div>

still no luck..

share|improve this question
This is not WordPress-specific and would be better asked on another site in the network, probably Stack Overflow. – Rarst Aug 3 '11 at 18:05

closed as off topic by Bainternet, t31os, Rarst Aug 3 '11 at 18:05

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

This should do the trick:

http://jsfiddle.net/tmort/u42UD/6/

jQuery:

$('.one').hover(

function() {

    $('.two').attr('id', 'one'); //box two's ID becomes box one
    $(this).attr('id', 'two'); //box one's ID becomes box two
}, function() {

    $('.two').attr('id', 'two'); 
   $(this).attr('id', 'one');

}); //end hover one

$('.two').hover(

function() {

    $('.one').attr('id', 'two'); //box two's ID becomes box one
    $(this).attr('id', 'one'); //box one's ID becomes box two

}, function() {

    $('.one').attr('id', 'one');
    $(this).attr('id', 'two');

}); //end hover one

HTML:

<div id="one" class="box one">Box One</div>

<div id="two" class="box two">Box Two</div>

I am using the classes to identify one and two as well as the ID's. That way, we can "remember" which is one and which is two when switching the ID's around.

Let me know if you have any questions and if this works

share|improve this answer
I just cant get it to work: – user385917 Aug 3 '11 at 15:54
Are you a developer? I can offer my development services if you would like. My website is at my user profile (click on my name). You can use the contact form to send me an email there. – Tom Aug 3 '11 at 16:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.