Im trying to get the string value of an img tag that is contained within a li tag that I have in my code using javascript.
The goal is to get all of the text contained in the img tag. But clearly I don't understand how to go that deep. When I try, I
The format of the html that Im trying to extract is...
<ol>
<li><img ......开发者_C百科/></li>
</ol>
Using what appears below, I get [object] returned instead of a string. Any idea on how to get the actual value of the string?
<script>
$(function() {
$( "#selectable" ).selectable({
stop: function() {
var result = $( "#select-result" ).empty();
$( ".ui-selected", this ).each(function() {
var index = $( "#selectable li img" );
result.append( " #" + ( index + 1 ) );
});
}
});
});
</script>
For the image source, try
var src = index.attr('src');
You can get any other attributes in the same way.
精彩评论