Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery implementing a simple search box function
    primarykey
    data
    text
    <p>So, I have to create a simple search box. In my right container I have made a search box like this:</p> <pre><code>&lt;div id="searchContainer" class="cf sb"&gt; &lt;div class="right magnifier"&gt;&lt;/div&gt; &lt;input class="right" type="text" id="searchBox" placeholder="search"/&gt; &lt;/div&gt; </code></pre> <p>In the main container I have multiple objects of the class newsItem.</p> <pre><code>&lt;div class="newsItem cf sb br"&gt; &lt;div class="closeButton right"&gt;&lt;/div&gt; &lt;div class="titles left"&gt; &lt;div class="Title"&gt;&lt;h3&gt;{{Title}}&lt;/h3&gt;&lt;/div&gt; &lt;div class="Subtitle"&gt;&lt;h5&gt;{{Subtitle}}&lt;/h5&gt;&lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="imageContainer"&gt;&lt;img src={{URI}} alt="" /&gt;&lt;/div&gt; &lt;div class="newsText"&gt;&lt;p&gt;{{Text}}&lt;/p&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Now, the search box, after entering some text in it and clicking the magnifier icon, should search the titles and the content of every object in the main container and remove those objects that don't have the searched text in them. If the search box is empty when clicking the magnifier, all the objects that have been removed should reappear. I have tried with the following jQuery function:</p> <pre><code>$("#searchContainer").on("click", "#searchContainer .magnifier", function() { var text=$("#searchBox").val(); var string=$(".newsItem .Title").text(); var string2=$(".newsItem .newsText").text(); var m=string2.search(text); if(text === "") { $(".newsItem").fadeIn(); } else if(text.length !== string.length || string.indexOf(text) !== 0) { if(m&lt;0) { $(".newsItem").fadeOut(); } } }); </code></pre> <p>but nothing happens after clicking the magnifier. I'm probably using the wrong selectors since I'm a complete beginner. Any help to make it work would be really appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload