I have an ul
list inside which li
are there, and inside li
text and div
are there. same
class is assigned to li
while div
are assigned with different class name.
I just want to get the text from li
and not from div
.
Here is the snippet:
$("ul li").on('click', function() {
$("span").text($(this).text());
});
ul {
position: relative
}
div {
position: absolute;
right: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class='same'>Text1
<div class='notsame'>Other text</div>
</li>
<li class='same'>Text2
<div class='notsame'>Other text</div>
</li>
<li class='same'>Text3
<div class='notsame'>Other text</div>
</li>
</ul>
<span> </span>
I get the O/P, but also text inside div come how to avoid that ?