Petar Bojić
Petar Bojić

Reputation: 35

DOM Manipulation help needed

<div id="main">
<div class="navigate">
    <ul>
        <li>
            <a href="http://localhost/xm/index.php"><span>xm</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin"><span>Admin</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin;change=name;random02342=randomvaluetoo320230"><span>change</span></a>
            .......

From this html code I have to get random generated data "random02342=randomvaluetoo320230" in variable, which is random generated both random0234 and random value too. How I can achieve this via Javascript (jquery or not)?

EDIT: random02342 and randomvaluetoo320230 is randomly server-side generated.. so its like every time new hash like 1stHash4324kjkjdas324324=And2ndAnotherHash324324asd23432

Upvotes: 2

Views: 118

Answers (3)

Felix
Felix

Reputation: 852

based on your comment:

var value = $('selector').attr('href').split(';')[2].split('=');

this will give you value[0] - name, and value[1] - value However this is only if there 3 query params and the random one is the third

Also this might be usefull Parse query string in JavaScript

Upvotes: 0

nbrooks
nbrooks

Reputation: 18233

var first, second;

var q = $('.navigate ul li a[href*="change=name"]').attr('href').split(';').filter(
    function() {
        return this.contains('random');
    }
).join().replace(/[a-zA-z]/g, '').split('=');

first = q[0];
second = q[1];

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

This would get it, though it's probably not going to win any awards for elegance:

var m = document.getElementById('main').innerHTML.match(/random(\d+)=randomvaluetoo(\d+)/);
// m[1] and m[2] are the two random values.

Upvotes: 2

Related Questions