Matching multiple keywords using contains() in jQuery

me9867

Currently matching a specific keyword using contains(). How can i expand this to include multiple keywords? have tried using the || (or) operator, but no joy.

<!-- Product names include Apple iPad, Acer Iconia, Lenovo Thinkpad -->

<h1 id="pbtitle">Apple iPad 3</h1>


<div class="install_option" style="display:none;">              
        <div style="box-sizing:border-box; float:left;">
            <a href="https://www.exmaple.com/acc" target="_blank">
                <h3 style="font-weight:bold;">Would you like to view accessories?</h3>
            </a>    
        </div>

</div>


$(".install_option").each(function() {
    if($("h1#pbtitle:contains:contains('Acer' || 'Lenovo' || Apple )").length>0){
      $('.install_option').css('display','block');
    }
});
VikingCode

Use JavaScript function indexOf()
Working example jsfiddle

var options = ['Acer','Lenovo','Apple']; // options that you want to look for
var text = $("#pbtitle").text();         // string where you want to look in

options.forEach( function( element ) {
    if ( text.indexOf( element ) != -1 ) {    // if its NOT -1 (-1 = not found)
      alert( 'found' );                       // then we found it .. do your magic
    }
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regexp for multiple keywords matching

From Dev

Keyword matching in an array/string of keywords using PHP

From Dev

Keyword matching in an array/string of keywords using PHP

From Dev

Recognizing multiple keywords using PocketSphinx

From Dev

Split using multiple keywords as demiliters

From Dev

Jquery "contains" multiple values

From Dev

Split using multiple keywords using regex

From Dev

Using multiple keywords in pyplot.axis in matplotlib

From Dev

Chrome extension using multiple omnibox keywords

From Dev

Using multiple keywords in xattr via _kMDItemUserTags or kMDItemOMUserTags

From Dev

search through a database using multiple keywords in php

From Dev

Using excel search function while there are multiple keywords

From Dev

AngularJS search multiple keywords using one field

From Dev

JavaScript – Issue using multiple keywords with RegExp

From Dev

String matching of a keyword using .contains() in Android

From Dev

JQuery contains not working multiple li

From Dev

Import Library contains no keywords

From Dev

Parsing, matching and keywords

From Dev

Matching text to keywords in Swift

From Dev

Using jQuery object of elements and :contains

From Dev

Using regular expression for fetching multiple keywords using python 3.4

From Dev

Returning multiple values using multiple matching criteria

From Dev

How to extract multiple line strings between two keywords using grepwin

From Dev

Search SQL database using multiple keywords entered in a TextBox

From Dev

Jquery Autocomplete matching multiple unordered words in a string

From Dev

Jquery matching multiple elements with same id/class

From Dev

Imported library 'ExcelLibrary' contains no keywords

From Dev

Matching keywords (strings) with a Pandas Dataframe

From Dev

Matching multiple occurrences in javascript using a regex

Related Related

  1. 1

    Regexp for multiple keywords matching

  2. 2

    Keyword matching in an array/string of keywords using PHP

  3. 3

    Keyword matching in an array/string of keywords using PHP

  4. 4

    Recognizing multiple keywords using PocketSphinx

  5. 5

    Split using multiple keywords as demiliters

  6. 6

    Jquery "contains" multiple values

  7. 7

    Split using multiple keywords using regex

  8. 8

    Using multiple keywords in pyplot.axis in matplotlib

  9. 9

    Chrome extension using multiple omnibox keywords

  10. 10

    Using multiple keywords in xattr via _kMDItemUserTags or kMDItemOMUserTags

  11. 11

    search through a database using multiple keywords in php

  12. 12

    Using excel search function while there are multiple keywords

  13. 13

    AngularJS search multiple keywords using one field

  14. 14

    JavaScript – Issue using multiple keywords with RegExp

  15. 15

    String matching of a keyword using .contains() in Android

  16. 16

    JQuery contains not working multiple li

  17. 17

    Import Library contains no keywords

  18. 18

    Parsing, matching and keywords

  19. 19

    Matching text to keywords in Swift

  20. 20

    Using jQuery object of elements and :contains

  21. 21

    Using regular expression for fetching multiple keywords using python 3.4

  22. 22

    Returning multiple values using multiple matching criteria

  23. 23

    How to extract multiple line strings between two keywords using grepwin

  24. 24

    Search SQL database using multiple keywords entered in a TextBox

  25. 25

    Jquery Autocomplete matching multiple unordered words in a string

  26. 26

    Jquery matching multiple elements with same id/class

  27. 27

    Imported library 'ExcelLibrary' contains no keywords

  28. 28

    Matching keywords (strings) with a Pandas Dataframe

  29. 29

    Matching multiple occurrences in javascript using a regex

HotTag

Archive