JQuery - get child input based on name selector

I have an onclick event that calls a function by passing the current div:

<div onclick="deleteline($(this));">

In my delete function, how do I get the child of the parent element of $ (this), where the name contains Qty?

In this example, I want to get the ProdQty input field:

<div>
    <input id="PrdQty" type="hidden" value="1">
    <div onclick="deleteline($(this));">
</div>

EDIT: This page becomes embedded several times in another page with an ajax call. Therefore, if I assign a clickable div ID, it will cause a conflict after this code is entered into the parent file a second time.

As a result, I used the sentences below, saved inline onclick and get qty with: sender.parent (). find ('input [id * = "Qty"]')

+3
source share
5 answers

CSS jQuery (http://api.jquery.com/category/selectors/)

, :

$(this).siblings("input[id*='Qty']")

, $(this), "Qty" id . , .first() , :

$(this).siblings("input[id*='Qty']").first()
+4

API jQuery?

// make it as specific as you need
$('div').click(function() {
    // do something
});

.parent([selector]) jQuery, . .prev([selector]), .

+2
   <div>
      <input id="PrdQty" type="hidden" value="1">
      <div id="getChild"></div>   // here I give an ID to you div.you can also  use class
   </div>


   // binding click event on #getChild div

    $('#getChild').on('click', function() {

       $(this).parent().find('input[id~="Qty"]');

    });

<div>
    <input id="PrdQty" type="hidden" value="1">
    <div onclick="deleteline(this);">
</div>


function deleteline($this) {
   $($this).parent().find('input[id~="Qty"]');
}
+1

onclick HTML, n unobutriveive. div,

<div>
  <input id="PrdQty" type="hidden" value="1">
  <div class="divtoCheck" />
</div>


$(function(){
    $(".divtoCheck").click(function(){
         var child=$(this).parent().find("input[id*='Qty']")
        alert(child.attr("id"));
    });

});

http://jsfiddle.net/gKnf3/10/

+1

, jQuery.

Here is the code I creaked: http://jsfiddle.net/luhn/RrczZ/

Change: . All the other answers seem to use an attribute containing a word selector that actually won't work ....

0
source

All Articles