0

See the following HTML: enter image description here

i need to get the value (417762) of this button. I"m trying to do it like this but it doesn't work (see the else clause beneath). I get "undefined" all the time.

$('#migrationssearchtable tbody').on('click',
            'td.details-control',
            function() {
                var tr = $(this).closest('tr');
                var row = table.row(tr);

                if (row.child.isShown()) {
                    row.child.hide();
                    tr.removeClass('shown');
                }
                else {

                    var v = tr.find(".details-control"); // this finds the HTML of the TD
                    var o = v.find(".btn btn-requeue"); // this does not work, gives undefined.  


                }
            }
        );
8
  • click on tbody? Commented Dec 19, 2017 at 7:42
  • 3
    missing . in last selector should be .btn.btn-requeue Commented Dec 19, 2017 at 7:43
  • 1
    var o = v.find(".btn-requeue"); Commented Dec 19, 2017 at 7:44
  • 1
    fix this class=" details-control" => class="details-control" Commented Dec 19, 2017 at 7:44
  • 1
    Also i think $(document).on('click', 'td.details-control', function() { is better. Commented Dec 19, 2017 at 7:48

2 Answers 2

2

Replace

var o = v.find(".btn btn-requeue");

With

var o = v.find(".btn.btn-requeue");

You can check the fiddle

http://jsfiddle.net/rgs5a1xy/5/

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

Comments

1

You're looking for v.find(".btn btn-requeue");. Notice that btn-requeue has not got a period in front of it. That means it jQuery will be looking for an element with a btn-requeuetag inside of the element with the btnclass.

The correct way would be .btn.btn-requeue, or just .btn-requeue.

I've changed it to v.find(".btn.btn-requeue"); in the code below, and that seems to do the trick.

$(function(){

	$('#migrationssearchtable tbody').on('click', 'td.details-control',function() {
		var tr = $(this).closest('tr');
  	var v = tr.find(".details-control"); // this finds the HTML of the TD

  	var o = v.find(".btn.btn-requeue"); 
   alert('the value is: '+o.val());
  });
  
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table id="migrationssearchtable">
<tbody>
<tr>
  <td class="details-control">
    <button class="btn btn-requeue" value="417762">
    ++
    </button>
  </td>
</tr>
</tbody>
</table>

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.