Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7911143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:08:34+00:00 2026-06-03T13:08:34+00:00

Given this HTML: <div id=TABLE1 class=tabs> <table> <tbody datasrc=Music> <tr id=randomid>lorem</tr> <tr id=foo>lorem</tr> <tr

  • 0

Given this HTML:

<div id="TABLE1" class="tabs">
    <table>
        <tbody datasrc="Music">
            <tr id="randomid">lorem</tr>
            <tr id="foo">lorem</tr>
            <tr id="abcde">lorem</tr>
            <tr id="fghijk">lorem</tr>
            <tr id="lmnop">lorem</tr>
            <tr id="qwerty">lorem</tr>
        </tbody>
    </table>
</div>
<div id="TABLE_2" class="tabs">
    <table>
        <tbody datasrc="Music">
            <tr id="random5">lorem</tr>
            <tr id="farhaf">lorem</tr>
            <tr id="haerf">lorem</tr>
            <tr id="hagasdg">lorem</tr>
            <tr id="hrfafh">lorem</tr>
            <tr id="qwerty">lorem</tr>
        </tbody>
    </table>
</div>
<div id="LASTTABLE" class="tabs">
    <table>
        <tbody datasrc="Music">
            <tr id="rtefdgag">lorem</tr>
            <tr id="wrtjfd">lorem</tr>
            <tr id="reaht">lorem</tr>
            <tr id="aggag">lorem</tr>
            <tr id="rthhre">lorem</tr>
            <tr id="argarg">lorem</tr>
        </tbody>
    </table>
</div>

I am trying to trigger 2 <tr>‘s from each table randomly. I cant even thing of the way doing this.

Currently for my test I use:

$("#button").on('click', function () {
    $('#randomid').trigger('click')
})

but this trigger’s only the first row from the first table.

So how can I:

  1. When I press #button,
  2. Get 2 random row’s from each table, Trigger
  3. click each row every 10 ms (so they have an order).

About the app:

It is a music player website. Each table has different style of music. Rock, Alternative, Jazz etc. There is a button ‘randomly select music’). That button, will trigger 2 random tr’s from each table so you end up with 2 jazz songs, 2 rock songs etc to be added to the playlist. The table looks something like this: http://dribbble.com/system/users/31916/screenshots/167289/k-dribble.png?1309036379 but those checkboxes are not actual checkboxes but images which change position on click to look and feel better than a checkbox and still act the same as a checkbox.

The user can trigger the ‘checkbox’ or choose a song by clicking anywhere on the row (logical), so the back-end is developed in a way to capture clicks anywhere on a row and not specificly the checkbox (thus I am not choosing to trigger those). I dont think there is a better solution that just trigger click randomly 2 row from each tble.

Support for IE8+.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:08:37+00:00Added an answer on June 3, 2026 at 1:08 pm

    See my version below,

    DEMO

    Note: Below code has some demo code and redundant vars which you can clean up, but I am leaving it there as to make the code look clear and self explanatory.

    $(function() {
        var $tables = $('table'); //gets the tree tables
    
        var mQ = []; //music queue
        var timer = null;
        $('button').click(function () {
            $('#result').html(''); //demo code
            var t = 0, $tr;
            var t1 = [];
            $tables.each(function () {
                $tr = $(this).find('tr');
    
                t1[0] = Math.floor(Math.random()*$tr.length);
                t1[1] = Math.floor(Math.random()*$tr.length);
    
                while (t1[0] == t1[1]) { //To make sure not same row is selected
                    t1[1] = Math.floor(Math.random()*$tr.length);
                }
    
                mQ.push($tr.get(t1[0]));
                mQ.push($tr.get(t1[1]));
            });
    
            timer = setInterval(function () {//Create timer to trigger click every 10ms
                if (mQ.length == 0) {
                    clearInterval(timer);
                    return false;
                }
                $(mQ.shift()).click().addClass('selected');            
            }, 10);
        });
    
        $('tr').click(function () {
            //do your magic
            $('#result').append(this.id + '<br />');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this HTML: <div id=foo> <input type=button class=foo abtn_1> <input type=button class=joe bbtn_2> <input
Given this HTML: <div id=foo> <input type=button class=foo abtn_1> <input type=button class=joe bbtn_2> <input
Given this HTML: <div>foo</div><div>bar</div><div>baz</div> How do you make them display inline like this: foo
Given this html: <div class=nation> <a href=library.php?type=nation&amp;id=America> <div class=nation-image> <img src=nations/America.png alt=snip /> </div>
Given this HTML: <div class=OpenIDSelector>some text</div> Why does this JQuery selector match it on
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
I'm trying to select an element given by: /html/body[@id='someid']/form[@id='formid']/div[@id='someid2']/div[@id='']/div[@id='']/div[@id='']/table/tbody[@id='tableid']/tr[7]/td[2] Now the html of that
Given the following HTML: <asp:content id=Content1 contentplaceholderid=mainContent runat=server> <div class=scrollRow> <table width=100%> <tr> <td
Given this HTML snippet: <div id=box style=overflow:auto; width:200px; height:200px; border:1px solid black;> 1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br> 11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>
content = ; $.each(data.response, function(i, y){ $(div#userBox_+id+ div#+tab+File).html(content); $(div#userBox_+id+ div#+tab+File tr.) content=<table class='crmTable'><tr><th colspan='3'>+y.email.email+</th></tr>;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.