0

So the last line of code selects all the "a" elements on the page that are within "transactiontable". I need it to only select the "a" element that lies with the current "tr" element as each URL for each "tr" element is unique.

Currently all the URLs have the same id value as from the last iteration of the for each function.

Any help would be greatly appreciated. Thanks

Ignore "[[ @{'~' + ${flowExecutionUrl}(_eventId='existingVehicle')} ]]" as that is Thymeleaf.

$(document).ready(function() {  
            $('#items-list tr').each(function() {
                var id = $(this).attr('id').split('-')[1];
                var url3 = "\u0026id=" + id;

                var url = [[ @{'~' + ${flowExecutionUrl}(_eventId='existingVehicle')} ]] + url3;

                $('.transactiontable a').attr('href', url);
            });
});

1 Answer 1

2

This should do it:

$(document).ready(function() {  
    $('#items-list tr').each(function() {
        var id = $(this).attr('id').split('-')[1];
        var url3 = "\u0026id=" + id;

        var url = [[ @{'~' + ${flowExecutionUrl}(_eventId='existingVehicle')} ]] + url3;

        $(this).find('.transactiontable a').attr('href', url);
    });
});

The '$(this)' selector represents the current item within the scope of the iterator, and 'find' then performs the selection within that element.

Sign up to request clarification or add additional context in comments.

2 Comments

A few words explaining what you're doing and why would make this a better answer.
Ah thank you! I had to edit out the ".transactiontable" part though for it to work. $(this).find('a').attr('href', url); Will mark as answer when 9 minutes are up.

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.