QA Graphic

Map - Jquery

Find the contents order using JQuery Map

jQuery map() function is useful when you want to verify that a list (unordered, ordered) are in the right order. Simple create the jQuery object as a Map array and then join it.

Sample Data

<div>
      <label for="two">2</label>
      <input type="checkbox" value="2" id="Boston" name="number[]">
    </div>
    <div>
      <label for="four">4</label>
      <input type="checkbox" value="4" id="Concord" name="number[]">
    </div>
    <div>
      <label for="six">6</label>
      <input type="checkbox" value="6" id="Stow" name="number[]">
    </div>
    <div>
      <label for="eight">8</label>
      <input type="checkbox" value="8" id="Carlisle" name="number[]">
</div>

Your jQuery Action

$( ":checkbox" )
  .map(function() {
    return this.id;
  })
  .get()
  .join();

Your Results would be:

"Boston,Concord,Stow,Carlisle"

Javascript results:

 return $( ":checkbox" )
  .map(function() {
    return this.id;
  })
  .get()
  .join()
  .includes("Boston,Concord,Stow,Lowell")

 

Comments

Add Your Comments

Name:
Comment:

 

About

jQuery is the most popular Javascript library on the Internet. Chances are that websites that your testing use it. These posts are all about tips and tricks for QA testing.

Schedule

Monday 14 Media
Tuesday 15 QA
Wednesday 16 Veed
Thursday 17 PlayWright
Friday 18 Macintosh
Saturday 19 Internet Tools
Sunday 20 Misc