check if any of element has a text - without each loop

how to check if all inputs are not empty with javascript
how to check multiple textbox is empty or not in jquery
jquery check if input has value
jquery check if input is not empty
check if input is empty javascript
jquery check if all required fields are filled
jquery check if input is empty on submit
jquery if text input not empty

I want to return false if any of mdpoptags has text as variable a. I want do this without each loop.

var a = 'ABBA'
if ($('.mdpoptag:contains(' + a + ')').length > 0) {
  console.log('323');
  //return false;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='mdpoptag'>ABBA</div>
<div class='mdpoptag'>ABB</div>
<div class='mdpoptag'>AB</div>

I've added some other examples to make it more generic. Let's say the action you want to execute on all your matched elements is .hide(), to make it simple.

Snippet using :contains():

var a = 'ABBA';

// If you want to execute a global action on all your elements, you can do the following:
var matched = $('.mdpoptag:contains(' + a + ')');
if (matched.length) {
  matched.hide();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='mdpoptag'>ABBA</div><!-- ABBA is here -->
<div class='mdpoptag'>ABB</div>
<div class='mdpoptag'>AB</div>
<div class='mdpoptag'>ABBABB</div>
<div class='mdpoptag'>BBABBA</div>
<div class='mdpoptag'>ABBA</div><!-- ABBA is here too -->

Love and Math: The Heart of Hidden Reality, In other words, to describe an element of this group we need n(n−1)/2 independent coordinates (in the case n = 3 we need 3(3−1)/2 = 3 coordinates, as we have seen in the main text). 9. Roughly speaking, this means that the loop does not have any sharp angles or It is easy to check that all axioms of the group hold. if you can to get one element from a list without looping you can use LINQ ( first,firstOrdefault, Single,SingleOrdefault) functions that can give you one element from you list, also if you need more than once you can use where with ToList at the end for the cast.all those functions take as parameters lambda expression.

I'm just guessing now becuase in my opinion the answer to your question is already in your question.

If you want to display only those divs that does not contain variable a value then you can do it like this

var a = 'ABBA',
  container = $('.mdpoptag:contains(' + a + ')');
  
if (container.length > 0) {
  container.hide();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='mdpoptag'>ABBA</div>
<div class='mdpoptag'>ABB</div>
<div class='mdpoptag'>AB</div>

Beginning JavaScript, Some plug—ins, such as RealPlayer, will not work reliably at all with this An alternative method for checking that a plug—in is installed is to loop plugins array, starting from index 0 and continuing up to the last element. Each plug-in in the array has its name property checked to see if it contains the text "RealPlayer. How to check if a string contains text from an array of substrings in JavaScript? loop and check the string against each substring in array without loop. 0.

You had a spelling error in your variable a content.

var a = 'ABBA';
if ($('.mdpoptag:contains(' + a + ')').length > 0) {
  console.log('found!');
  //return false;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='mdpoptag'>ABBA</div>
<div class='mdpoptag'>ABB</div>
<div class='mdpoptag'>AB</div>

C# 2008 Programming: Covers .Net 3.5 Black Book, Platinum Ed, Set the Text property of the buttons to Show all elements , Show last names We have then created an object of the XmlReader class by calling the Create Inside the loop , we have checked if the current node is of type XmlNode Type . If not , we move to the next node by using the Read method of the XmlReader object  Here, item is the object which is to be locate in the List<T>. The value can be null for reference types. Return Value: This method returns True if the item is found in the List<T> otherwise returns False. Below programs illustrate the use of List<T>.Contains(T) Method: Example 1: // C# Program to check whether the.

AngularJS: Up and Running: Enhanced Productivity with Structured , The scope dictates what each DOM element has access to in terms of Instead of polling or some other mechanism to check if the data has changed, That template accesses a variable called note, which is created in our for each loop that is the accessed the same context, each instance would show the same text​. Output: 8 has occurred 5 times Method 2 (Using Counter()) Counter method returns a dictionary with occurrences of all elements as a key-value pair, where key is the element and value is the number of times that element has occurred.

Jquery Plugin Development Beginner's Guide, We have to take care ofafew things now: Check if the element is actually a link (​who knows!) We can then add the following code at the verystart of the each loop. not show up (note wefirst save the title content so thatwe canuse its text later  B = any(A,vecdim) tests elements based on the dimensions specified in the vector vecdim.For example, if A is a matrix, then any(A,[1 2]) tests over all elements in A, since every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

JavaScript Array every() Method, The every() method checks if all elements in an array pass a test (provided as a Note: every() does not execute the function for array elements without values. You can stop the loop from within the callback function by returning false. Note: most jQuery methods that return a jQuery object also loop through the set of elements in the jQuery collection — a process known as implicit iteration. When this occurs, it is often unnecessary to explicitly iterate with the .each() method:

Comments
  • use a filter
  • I'm sure jQuery does use a loop internally to implement contains - why not use one yourself?
  • Use filter() to get an exact match, however you should still note that jQuery is looping through the elements internally (as there's no other way to do this), so the 'no loop' requirement is rather odd
  • How to set filter - criteria argument in the above case, pls
  • @puerto Your code works properly. There is no div with string ABBA; There is a div with string ABBA though. You have a typo.
  • Thanks, you helped me to find the final sollution.
  • @puerto Glad it helped. :)