I’m building basically a visually appealing version of an option-select element.
I’m making a ul that will have a .selected class applied to whatever item is clicked.
<ul id="videolist" class="tilelist">
<li id="video-'. $video-id .'">
<img src="assetsPath/etc/'. $video-thumb .'" />
<h4>'. $video-title .'</h4>
<p class="hidden vid-id">'. $video-id .'</p>
</li>
';} ?>
</ul>
<input id="videoId" class="hidden" value="<?php echo $current->video ?>" />
and then some jquery:
$(function(){
$('#videolist li').click( function() {
$('#videolist li').removeClass('selected');
$(this).addClass('selected');
var vidId = $(this).find('.vid-id').val();
alert (vidId);
$('#videoId').val( vidId );
});
});
the issue is with $(this).find('.vid-id').val(); doesn’t seem to be returning anything. I don’t see anything wrong with the selector but I am a bit new to jquery.
What you are looking for is
text()notval()if you are meaning to pull this from theptag.If you want to pull it from the
inputyou’re going to have to select the id like this:$(this).find('#videoId').val();Also, you don’t need to add css properties to hide the input, you can just do
type="hidden"