Roger
Roger

Reputation: 8576

JQuery Filter Tag Value

I am trying to select a clicked "a class mail" href value in order to filter it and add a one word string after the text "...subject=[Site]..." to be like this: "...subject=[Site] string..."

envie um e-mail para [email protected]

This is as far as I can go:

$('a.mail').click(function(event){ $(this).prop('href',$(this).prop('href').replace('[Curso]', '[Curso] some text')); });

I replaced prop by attr but it did not work...

$('a.mail').click(function(event){ $(this).attr('href',$(this).attr('href').replace('[Curso]', '[Curso] some text')); });

Upvotes: 0

Views: 246

Answers (2)

Luis Aguilar
Luis Aguilar

Reputation: 4381

First, I would like to invite you to write code as readable as you can. Here's how I would do what you're trying to achieve:

$('a.mail').click(function (event) {
    var $this = $(this);
    var linkUrl = $this.attr('href');

    linkUrl = linkUrl.replace('[Curso]', '[Curso] some text');
    $this.attr('href', linkUrl);
});

Upvotes: 1

c-smile
c-smile

Reputation: 27470

Use attr() instead of prop() as these are different things.

Upvotes: 1

Related Questions