Moti Mashiah
asked on
Jquery
Hi guys,
I have jquery code and I want to do on click button go to my ul and grab my first li.
i did something like this which is not workin:
I have jquery code and I want to do on click button go to my ul and grab my first li.
i did something like this which is not workin:
<ul id="myulid">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<input type="button" id="btnid" value="clickMe">
<div id="addone">
</div>
@section scripts{
<script>
$(document).ready(function () {
debugger;
$("#btnid").click(function () {
var test = $("#myulid").select("li:first");
$("#addone").append(test.text());
});
});
</script>
}
$('#btnid').on('click',function(){
var test = $('li').first();
$("#addone").append(test.text());
});
Tested in liveweave
ASKER
Leonidas,
Thank you for your answer. can you give me example with select as well?
like var test = $("#myulid").select("li:fi rst");
Thank you for your answer. can you give me example with select as well?
like var test = $("#myulid").select("li:fi
$('#btnid').on('click',function(){
var test = $('li:first');
$("#addone").append(test.text());
})
ASKER
I can't do it that why as I have many ul in this page:
Please can you correct my syntax:
I have to choose the ul id - myulid then the il.
<ul id="myulid">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
$("#btnid").click(function () {
var test = $("#myulid").select("li:fi rst");
$("#addone").append(test.t ext());
});
Please can you correct my syntax:
I have to choose the ul id - myulid then the il.
<ul id="myulid">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
$("#btnid").click(function
var test = $("#myulid").select("li:fi
$("#addone").append(test.t
});
$('#btnid').on('click',function(){
var test=$('ul#myulid li:first');
$("#addone").append(test.text());
})
In this code you can choose the ul via the id.
ASKER
Thank you that is working just fine,but still I would be happy to have something with "select"
like var test = $("#myulid").select('li:fi rst')
I don't know why this is not working for me.
Thanks,
like var test = $("#myulid").select('li:fi
I don't know why this is not working for me.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did it many times before and it works so anyways I will use the code you gave me thank you.
btw, I can't click on best solution as it grays out.
Do you have an idea why ?
btw, I can't click on best solution as it grays out.
Do you have an idea why ?
ASKER
k, thank you.
ASKER