0

I have the following jquery function. It will only update the first row and then stops. Strangely though if i take out the line:

$("#prev_loan_approval_date").html("Not Yet Approved");

and replace it with an alert it fires off for each row. Is there any reason why this would be the case. Was thinking it mightnt return true on the next iteration because i changed the text value but this was for the previous row so the next row should still return true and change the value.

$(document).ready(function() {
    $('.loan_history_application > tbody  > tr').each(function() 
    {
        if ($("#prev_loan_approval_date").text() == "01/01/1900")
        {
            $("#prev_loan_approval_date").html("Not Yet Approved");
        };
    });
1
  • Can you also show the HTML? Commented Aug 13, 2015 at 10:02

4 Answers 4

2

tr has a child "#prev_loan_approval_date"? If yes, you must write

$(document).ready(function() {
    $('.loan_history_application > tbody  > tr').each(function() 
    {
        if ($(this).find("#prev_loan_approval_date").text() == "01/01/1900")
        {
            $(this).find("#prev_loan_approval_date").html("Not Yet Approved");
        };
    });
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't address the fact that there shouldn't be multiple elements with the same ID
@kiko That did it for me. Thanks. Will mark it as correct in 4 minutes...when it lets me.
HTML ID's must be unique per page. This is letting you have the same ID exist in every row. It may appear to work due to browser quirk, but it is not right.
0

The problem is likely to be that you use an ID instead of class for $("#prev_loan_approval_date").html("Not Yet Approved"); so it will only update the first row.

Change this to:

$(".prev_loan_approval_date").html("Not Yet Approved");

And make sure you also change ID to class in your HTML.

1 Comment

This doesn't search for that element per row
0

Was thinking it mightnt return true on the next iteration because i changed the text value but this was for the previous row

No, this isn't for the previous row. There's several things wrong here. Firstly the fact that you're using an ID for something that seems to occur more than once (ID's must be unique). You should use a class.

Secondly, where you're changing the text - you're not doing it just for that row. You're always doing it on every row.

$(document).ready(function() {
$('.loan_history_application > tbody  > tr').each(function() {
    if ($(".prev_loan_approval_date", this).text() == "01/01/1900")
    {
        $(".prev_loan_approval_date",this).html("Not Yet Approved");
    };
});

And in your HTML change id='prev_load_approval_date' to class='prev_loan_approval_date'

Comments

0

If you have multiple items with the same ID, it doesn't work. IDs should be unique. Change them to class and change in your code:

$(".prev_loan_approval_date").html("Not Yet Approved");

Full Code:

$(document).ready(function() {
    $('.loan_history_application > tbody  > tr').each(function() {
        if ($(this).find(".prev_loan_approval_date").text() == "01/01/1900")
            $(this).find(".prev_loan_approval_date").html("Not Yet Approved");
    });
});

3 Comments

This doesn't search for that element per row
The full code is in the question. If you want, I can update my answer with the full one.
@DalHundal Have a look now.

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.