jQuery overlay on multiple divs..only working on first div...

I've got a page with multiple divs indicating a news item in a CMS i'm building.

Each news item has it's on div called #new-item and is wrapped in it.

Inside that div is the content for the item and a div with a class of .new-item-overlay which has a 0 opacity upon loading.

My jquery is set to reveal the overlay which will indicate that clicking on it at that point will bring up editing options.

THE PROBLEM IS THAT ONLY THE FIRST NEWS-ITEM DIV ON THE PAGE IS GETTING THE ACTION TO ACTIVATE THE OVERLAY...

<script language="javascript">
$(document).ready(function(){
	
$("div.news-item-overlay").hover(
function() {
$(this).animate({"opacity": "0.60"}, "fast");
},
function() {
$(this).animate({"opacity": "0"}, "fast");
});			  		   		   
</script>

Open in new window



My html has divs like the following:

<div id="news-item">
      <div class="news-item-overlay">edit this item</div>
      <img width="100" height="100" />
      <p>News Item Content - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
    <div id="news-item"><div class="news-item-overlay">edit this item</div><img width="100" height="100" />
      <p>News Item Content - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>

Open in new window


The css for #news-item and .news-item-overlay is:

#news-item {
	float:left;
	width:875px;
	height:150px;
	margin:25px 0px 0px 25px;
	background-color:#333;
	cursor:pointer;
}
.news-item-overlay {
	position:absolute;
	left:0px;
	top:0px;
	width:875px;
	height:150px;
	margin:25px 0px 0px 25px;
	background-color:#000;
	z-index:2;
	cursor:pointer;
	color:#FFF;
	line-height:150px;
}

Open in new window


I'm guessing there is something i'm missing that's staring me right in the face...anybody know what's up?
dvointeractiveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McOzCommented:
The issue is that you have multiple divs with the same ID ("news-item"). This is causing the problem, as IDs are supposed to be unique.

Use classes instead, like
<div class="news-item">
      <div class="news-item-overlay">edit this item</div>
      <img width="100" height="100" />
      <p>News Item Content - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
    <div class="news-item"><div class="news-item-overlay">edit this item</div><img width="100" height="100" />
      <p>News Item Content - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>

Open in new window


and  
.news-item {
        float:left;
        width:875px;
        height:150px;
        margin:25px 0px 0px 25px;
        background-color:#333;
        cursor:pointer;
}

Open in new window


Cheers
0
McOzCommented:
Or else have unique IDs for each div, otherwise they would all open at once? :-)
0
dvointeractiveAuthor Commented:
@McOz

That still does not seem to work, I get the same result. I switched the css and the html to call the class instead of id...I get the same result: only the first div gets an overlay on hover...
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

liveaspankajCommented:
class is a good point +
also try changin the follow at line 4:(remove the div)

$(".news-item-overlay").hover(
0
dvointeractiveAuthor Commented:
I tried targeting the child div (the overlay) of the current hover too...didn't work. Though now the second div in the page activates the first divs overlay when hovered on too.

$(".news-item").hover(
function() {
$(this).children("div").animate({"opacity": "0.60"}, "fast");
},
function() {
$(this).children("div").animate({"opacity": "0"}, "fast");
});

Open in new window

0
liveaspankajCommented:
do you want effect on "edit this item" or the content in <p> or all?
0
dvointeractiveAuthor Commented:
@liveaspankaj

On the overlay and aything contained within it.
0
liveaspankajCommented:
the overlay div contains only the message "edit this item"

if you want everything you should do this:


$(".news-item").hover(
function() {
$(this).animate({"opacity": "0.60"}, "fast");
},
function() {
$(this).animate({"opacity": "0"}, "fast");
});


if you want only the message in the <p> tag:

$(".news-item").hover(
function() {
$(this).children("p").animate({"opacity": "0.60"}, "fast");
},
function() {
$(this).children("p").animate({"opacity": "0"}, "fast");
});
0
dvointeractiveAuthor Commented:
liveaspankaj

Doesn't work.

Here's a live sample of what's going on - http://hover.dvointeractive.com/

The way the overlay works on the first item is perfect.

Notice that hovering on the second item activates the overlay on the first item instead of itself...

That's what needs to be fixed.
0
liveaspankajCommented:
i found the problem.


.news-item-overlay {
      position:relative;
      left:0px;
      top:0px;
      width:875px;
      height:150px;
      margin:25px 0px 0px 25px;
      background-color:#000;
      z-index:2;
      cursor:pointer;
      color:#FFF;
      line-height:150px;
}

the position in the css above has to be relative and not absolute. otherwise all the elements will pileup the overlays at the sameplace. then you will have to do some css to make it look proper. but its sure that you cannot use absolute position for all the overlay elements
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.