dotty
dotty

Reputation: 41433

.attr("href") with links containing commas

Hay i have a link like this

index.php?sometext=f,fsdsd,rerw,e,wewewe

and when i use .attr("href") on the link, it stops at the first comma, so it only displays

index.php?sometext=f

Any idea how to get ALL the href value

Upvotes: 1

Views: 2117

Answers (3)

andres descalzo
andres descalzo

Reputation: 14967

$('a').each(function(i, el){

    var href = $(this).attr('href');

    if (href.split('?').length == 2) {
        var dir = href.split('?')[0], query = href.split('?')[1];
        $(this).attr('href', dir + '?' + encodeURI(query));
    }

});

encodeURI

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 881735

Commas are among the characters that should be urlencoded when present in a URL, that is, in their case, replaced with %2C.

Upvotes: 0

Ivan Nevostruev
Ivan Nevostruev

Reputation: 28723

You should replace , with %2C in your links. This is URL encoding.

Upvotes: 2

Related Questions