-1

I am cloning contentdiv, the new clone div input element value has been increase upc0 to upc1. But I'm unable figure it out how to find description0 id. During cloning I'm getting undefined value. From description id I have to parse the integer value. Through this value only I'll change clone input element.

I've got a div in an HTML Page of which the name is always known and inside this div there is an href, the details of which are not known. It could be the direct child of the parent or it could be a further grandchild. Looks something like this:

Anybody help me please.

<div class="row-fluid" id="contentdiv">
<div class="span2">
    <div id="divupc" class="form-group">
        <label>UPC</label>
        <input class="form-control" type="text" id="upc0" name="upc0" placeholder="UPC"/>
    </div>
</div>
<div class="span2">
    <div id="divdescription" class="form-group">
        <label>Product Name</label>
        <input class="form-control" type="text" id="description0" name="description0" placeholder="Product Name"/>
    </div>
</div>

</div>
<button class="btn btn-success" type="button" name="additem" id="additem"><i class="fa fa-plus-circle fa-fw"></i>Add New Item</button>


<script>
$("#additem").click(function(){
$('#gmail_loading').show();
var clonedRow = $('#contentdiv :last').clone();
var rowID_old = $("input[id^='description']",clonedRow).attr("id");
alert(rowID_old);**// Here I'm getting undefined, I need description0 value**

});

Thanks in Advance

Pete
  • 57,112
  • 28
  • 117
  • 166
selva316
  • 11
  • 4

1 Answers1

0
$("#contentdiv div.span2:last input").attr("id");
or 
$("#contentdiv div.span2:last input[name=description0]").attr("id");
Sagar
  • 259
  • 2
  • 3
  • 14