Link to home
Start Free TrialLog in
Avatar of Yakup K
Yakup K

asked on

pass the previous tr td content into the link href

I had this question after viewing Adding a link on the nested data table.

I would like to pass the the department name into the export link, which I have created in drawcallback

So the link should be like that;

 $(".export").on("click", function(){
		 console.log("button is clicked");
       
    $(this).attr("href", "departmentName={departmentName}");

});

<a class="export" href="#" target="_blank">Export</a>
href= should be the parent first td ( department name) 

Open in new window


Any helps would be really appricated.

Thanks
JSFiddle
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

If you want the text from the first <td> of the <tr> that contains the link, then something like this:

$(".export").on("click", function(){
    console.log("button is clicked");
    dept = $(this).closest('tr').children('td:first').text();
    $(this).attr("href", "departmentName=" + dept);
});

Open in new window

Avatar of Yakup K
Yakup K

ASKER

Thanks for your comment Chris. Unfortunately, this is taking the next tr td content.

I would like to get the previous tr and second td ( Which is department name) .
This is the output for your script.
Export departmentsSearch:namephonehire_dateidOrigenes Maxwell345892February 1, 20046234Previous1Next

Please see the jsfiddle
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yakup K

ASKER

Thanks Chris. This one works perfectly.
No worries. Glad I could help
Avatar of Yakup K

ASKER

Hi Chris, When I click on the pagination, It duplicated the anchor links. For example, if there are 4 pages it duplicates the link for 4 times. Any ideas on this ?
Not sure about that. It seems like it's a completely different issue to the one raised in this question, and is probably more about how you're creating the data in the first place.

It makes sense to open a new question to ask about that specific problem