dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: JavaScript Using query SelectorAll

  1. #1
    Join Date
    Feb 2012
    Posts
    3

    JavaScript Using query SelectorAll

    First of all I'm a newbie in JavaScript so be patient.

    Here is what I want to do. There are several unique links that are returned from a search. I want to be able to use JavaScript's querySelectorAll() to grab the collection of these links and be able to click on any one in the collection.

    I've started with the following and it works great if I just want one link in my_results but I want all of the links on the page that represents the following format regardles of the "4N2mka256C4" digits.

    var my_results = document.querySelectorAll('a[href="/iac/viewAlert.do?alertId=4N2mka256C4="]');

    Again, I believe the problem is with these unique "4N2mka256C4" digits. However I do not know for sure. I thought about using reg expressions to get all the links regardless of those 11 digits, but I'm a newbie with reg expressions also.

    Please help.

    -----------------------------------------------------------------------

  2. #2
    Join Date
    Feb 2012
    Posts
    3
    A bit of more info:

    <a href="/iac/viewAlert.do?alertId=4N2mka256C4=" id="actiondefault_0">test</a></td>
    [...]
    <a href="/iac/viewAlert.do?alertId=3C2mka23er4=" id="actiondefault_1">test</a></td>
    [...]


    Please help...

  3. #3
    Join Date
    Feb 2012
    Posts
    3
    The following is the solution. It grabs the first column of the returned search results and the code identifies the links within the cells and places them (links) into the collection my_links. Then it chooses a number from my_links.length and randomizes it for a selection to be used later on.

    var my_links = document.querySelectorAll("#TableResult>tbody>tr>td:nth-of-type(1)>a");

    my_links[Math.floor(Math.random() * my_links.length)];


    I'm still going to try to solve this using reg expressions.

    Thanks,

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles