Ad

How Can I Search For Any Meta Tag Where Name Starts With "ABC_" Or "XYZ_" Using JQuery

- 1 answer

I have multiple <meta> html tags. I need to use jQuery to get all the meta tags where name starts with "ABC_" or "XYZ_" then loop through them.

Here is what I have done.

var tags = $( "meta[name^='ABC_']" );

$.each(tags, function(index, tag){
   //print the value of each tag
   console.log( $(tag).attr('value') );
});

The only problem is that I need to also search for any name that starts with "ABC_" or "XYZ_" not just "ABC_"

How can I add "XYZ_" to the mix

Ad

Answer

You can combine multiple selectors in a single selector by connecting them with comma.

$( "meta[name^='ABC_'], meta[name^='XYZ_']" )

This will return elements that match either selector.

Ad
source: stackoverflow.com
Ad