0

I have a table , in some of <td> , I have an anchor tag with values . I have to find the value of this by looping. Here is what I am trying:

$(tr).find('td').each(function() {

  var cells = $(this).html();
  var check = $(cells).find("a");
}

I am getting an error at : var check = $(cells).find("a"); because the first <td> value is "SomeText" and second <td> value is

Edit:

 "<input id="1"> <a > 188</a></input>"

I am trying to extract the output as 188

6
  • 3
    Why not do $(tr).find("td a")? Commented Oct 24, 2016 at 5:39
  • <input id="1" <a > 188</a><input is invalid html Commented Oct 24, 2016 at 5:41
  • 2
    Please edit your question to show a sample of the HTML. If the TD's "value" is "<input id="1" <a > 188</a><input" then you've got invalid html. Why are both inputs missing a closing >? Commented Oct 24, 2016 at 5:41
  • the problem is that you are using $ on an invalid selector, therefore the jquery results in an empty set of elements, which of course wont have an a tag in them Commented Oct 24, 2016 at 5:43
  • all you need is var check = $(this).find("a"); Commented Oct 24, 2016 at 5:44

1 Answer 1

1

Try this one,

$(document).ready(function(){
    $('table > tbody  > tr > td > a').each(function() {
        console.log(this.innerHTML);
    });
});
Sign up to request clarification or add additional context in comments.

Comments

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.