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
Yakup KAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
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

Yakup KAuthor Commented:
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
Chris StanyonWebDevCommented:
So you need the second TD from the previous TR ??

What about this:

dept = $(this).closest('tr').prev('tr').children('td').eq(1).text();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Yakup KAuthor Commented:
Thanks Chris. This one works perfectly.
Chris StanyonWebDevCommented:
No worries. Glad I could help
Yakup KAuthor Commented:
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 ?
Chris StanyonWebDevCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.