I've read all relevant posts but there must be something I am missing. I have a HTML doc that resembles below:
<!DOCTYPE html>
<html>
<head lang="en">
</head>
<body>
<div>
<h1 class="hoverClass">HOVER ITEM</h1>
</div>
<ul class="listContainer">
<li class="listItem" >
<div class="image">
<img class="contentImg" src="#"/>
<h5 class="innerText">text1</h5>
</div>
<p class="outerText">Text2</p>
</li>
<li class="listItem" >
<div class="image">
<img class="contentImg" src="#"/>
<h5 class="innerText">text1</h5>
</div>
<p class="outerText">Text2</p>
</li>
<li class="listItem" >
<div class="image">
<img class="contentImg" src="#"/>
<h5 class="innerText">text1</h5>
</div>
<p class="outerText">Text2</p>
</li>
<li class="listItem" >
<div class="image">
<img class="contentImg" src="#"/>
<h5 class="innerText">text1</h5>
</div>
<p class="outerText">Text2</p>
</li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="indexjs.js"></script>
</body>
</html>
I want to select each element of class 'listItem' so that i can dynamically alter the src of contentImg and the text of innerText and outerText.
I only seem to be able to select all or none. For instance the code:
$('.hoverClass').hover(function(){
var li = $(".listContainer").children().length;
var title = $(this);
title.text(li);
});
Will show the number of list items and
var li = $(".listContainer").hide();
will hide all of the items but
var li = $(".listContainer").children()[0].hide();
Does not hide the first list item div (class='image') - which I believe would be the first child element.
I have also tried using
var node = document.getElementByClassName();
using both 'contentList' and 'image' and have not been able to iterate through an array of results or index for an individual element.
Can somebody tell me what I'm doing wrong or misunderstanding.... Thanks