Nathan Riley
asked on
jQuery Selection Help
How can I select the input value of #assetID from the below when I click on .check
Here is my current jquery code, just not sure how to select the assetID.
<div class="col-md-12 noPadLeft raHolder" style="margin-top:20px;padding-right:30px;">
<input type="hidden" id="assetID" value="91">
<div class="col-md-7" style="margin-bottom:10px;">
<img src="images/postedDateTwitter.png" style="margin-right:5px;"> <span class="postedDate">Scheduled for May 09 2015 at 02:00 PM</span>
</div>
<div class="clearfix"></div>
<div class="col-md-12 borderB noPadLeft noPadRight" style="margin-left:15px;margin-right:15px;">
<div class="col-md-9 noPadLeft noPadRight" style="margin-bottom:20px;font-size:14px;color:#696a6c;">
Picture of logo. </div>
<div class="col-md-3 noPadLeft noPadRight text-right">
<div class="pull-right"><a href="#">EDIT</a></div><div class="checkDeny pull-right" style="margin-left:10px;margin-right:10px;"></div><div class="check pull-right"></div>
</div>
</div>
</div>
Here is my current jquery code, just not sure how to select the assetID.
<script>
$(".check").click(function(){
$.ajax({
type: 'POST',
url: 'submit.php',
data:
{
assetID: $("#ueCoName").val(),
orgID: <?php echo $orgID;?>,
userID: <?php echo $userID;?>,
submitType: 9
},
success: function(r)
{
$(this).closest(".raHolder").fadeOut("slow");
}
});
});
</script>
How about this?
$(this).parent('div.col-md-3').next('input#assetID').val()
ASKER
Not sure, just ended up getting it done with this, not sure if you way or this is better?
$(".check").click(function(){
$.ajax({
type: 'POST',
url: 'submit.php',
data:
{
assetID: $(this).closest(".raHolder").find('input').val(),
orgID: <?php echo $orgID;?>,
userID: <?php echo $userID;?>,
submitType: 9
},
success: function(r)
{
//Doesn't exist
//alert('Email preferences updated');
//console.log(r);
}
});
$(this).closest(".raHolder").fadeOut("slow");
});
Confused
#assetId implies an id - which must be unique per page
Therefore, the correct way to do this is
#assetId implies an id - which must be unique per page
Therefore, the correct way to do this is
$('#assetId').val();
ASKER
The assetID is not unique, it's dynamic and inserted during page load via php.
I have several #assetID's on the page in each of the boxes. Maybe I named incorrectly? But seems to be working now with the above solution.
I have several #assetID's on the page in each of the boxes. Maybe I named incorrectly? But seems to be working now with the above solution.
id's by definition must be unique - if you have multiple elements on your page with the same ID then your page is not valid and you should consider changing your design.
IF you do have multiple then you are going to run in to serious problems with selectors in javascript / jquery.
My advice - change your id's names.
IF you do have multiple then you are going to run in to serious problems with selectors in javascript / jquery.
My advice - change your id's names.
ASKER
Got it, so it should be a class instead?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window