Karim Ali
Karim Ali

Reputation: 2453

How can I convert text into link using Jquery and assign a function using Jquery?

How can I convert text into link using jQuery and assign a function? I have a table and I want to convert table’s last row’s first cell text into link and assign onclick function “DisplayDetails()”.

My table name is “ScoreCardDataCurrentTable”.

Upvotes: 0

Views: 675

Answers (3)

user618094
user618094

Reputation: 16

Try:

var cell = $('#ScoreCardDataCurrentTable tr:last td:first');

var text = $(cell).text();

var link = $('<a />').text(text).bind('click', function(){
    // your code here
    DisplayDetails();

});

$(cell).html(link);

// I'm assuming that your table has an ID of ScoreCardDataCurrentTable

Upvotes: 0

BiAiB
BiAiB

Reputation: 14161

var myCell = $('#mytable>tr:last>td:first');
var myContents = myCell.html();

//We do not use onclick attribute cause it may bring hell to our known world
var pseudoLink = $('<a>'+myContents+'</a>').click( function() {
  //Stuff here
});

Upvotes: 0

Chris
Chris

Reputation: 27394

$("#ScoreCardDataCurrentTable").children("tr:last").children("td:first").click(function(){
   DisplayDetails()
});

This code will set call DisplayDetails() when the first cell of the last row in the table is clicked. If you want the text itself to call the function you will have to tell us what the text is contained in.

it may be simpler just to use a link with an id and use CSS to style it how you like.

Upvotes: 1

Related Questions