1

Hi jQuery script does not add display block for all same mane divs, only for the first one.

JS

$("#sidecontrol_container").mouseenter(function(){
    setTimeout( function(){
    $('#packet_name').css('display','block');
       },310);
$( "#sidecontrol_container" ).animate({
        width:"230px"
    }, 300 );       
});
$("#sidecontrol_container").mouseleave(function(){
    $('#packet_name').css('display','none');
    $( "#sidecontrol_container" ).animate({
        width:"40px"
    }, 300 );   
});

HTML

<div id="sc_wraper">
    <div id="packet_name">1</div>
</div>

<div id="sc_wraper">
    <div id="packet_name">1</div>
</div>

CSS

#packet_name{
    height:40px;
    width:190px;
    float:right;
    display:none;
}

It only adds for first div with name packet_name <div id="packet_name" style="display:block;">1</div>

HTML RESULT after mouseenter

<div id="sc_wraper">
        <div id="packet_name" style="display:block;">1</div>
    </div>

    <div id="sc_wraper">
        <div id="packet_name">1</div>
    </div>
3
  • 1
    You need to use div classes instead, IDs are only for single occurrences on a page. Then adjust your jQuery as appropriate Commented Apr 20, 2014 at 1:17
  • @robobobobo why don't you add that as an answer? Your suggestion seemed to have worked for Vadimas. Commented Apr 20, 2014 at 1:27
  • Sure thing jsve, added it now, thanks Commented Apr 20, 2014 at 1:32

1 Answer 1

2

The reason it is only changing the first one is because jQuery only selects the first instance of the div name since its an ID.

If you want to change multiple divs of the same name you need to use div classes instead for their names. Once you update your html to use class names, do the same with jQuery and it should work

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

1 Comment

OMG. such a silly mistake but I wouldn't have thought of it (I'm relatively new to these languages.) Thank you!!

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.