0

I was trying to wrap a Achor tag to the Email-id dynamically, I am facing issues below is my html code:

<tr>
  <td id='label'>
    email
  </td>
  <td>
    <div>
      [email protected]
    </div>
  </td>
</tr>

and jquery code which i am trying is wraping the Achor tag to the div :

$("tr td#label:contains('email')").next().each(function(){ 

   $(this).wrapInner('<a href="mailto:'+$(this).text()+'">');

});

i what to wrap a Achor tag to Email-Id. how can i do this?

3
  • Should that not be $("#label:contains('email')").next("div").. the ID is supposed to be unique Commented Jun 27, 2013 at 8:53
  • Your code seems to be working fine here Commented Jun 27, 2013 at 8:54
  • but the Achor tag is above the div. Commented Jun 27, 2013 at 8:58

1 Answer 1

1

First modify markup to use class insted of id :

<tr>
  <td class='label'>
    email
  </td>
  <td>
    <div>
      [email protected]
    </div>
  </td>
</tr>

Script:

$(".label:contains('email')").each(function(){
    var email = $(this).closest('td').next('td').find('div').text();
    $(this).html('<a href="mailto:'+email+'">email</a>');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.