jQuery Selector find equal something

Using jQuery each find something

<script type="text/javascript">

var searchItem = "searchItem";
var searchValue;
$("select").find("option").each(function(n){
    if($(this).val() == searchItem) {
        searchValue = $(this).attr("data-searchvalue");
    }
});

</script>

Using jQuery selector attribute find something

<script type="text/javascript">

var searchItem = "searchItem";
var searchValue = $("select").find("option[value='"+searchItem+"']").attr("data-searchvalue");

</script>

Comments

Leave a Reply