jqueryconditional-statements

Inside list condition with jQuery


I'm trying to build a jQuery function that triggers a specific event if the content of a META Tag is contained in a list of words.

I've tried:

<meta name="sun" content="a" >

<script>

$('meta[name=sun]').each(function(){
    var metacontent = $(this).attr("content");
    var list = ["a","b","c"];

if(metacontent.match(list)) { //that is wrong I guess
    console.log("hi");

}
});
</script> 

Can you give me a hint?


Solution

  • you can try the jQuery utility function $.inArray

    if($.inArray(metacontent, list) >= 0) {
    .....