I have a loop event with a matching condition. The problem is the matching can happen more than once. I only want the first matched result. This is some script:
<div class='container_a'>
<div class='user user_name' id="user_shipment_name">John</div>
<div class='user user_type' id="user_shipment_type">Admin</div>
</div>
<div class='container_b'>
<div class='user user_name' id="user_payroll_name">Ray</div>
<div class='user user_type' id="user_payroll_type">Staff</div>
</div>
The jQuery:
$(".user").each(function(i){
var user_match = $(this).first().prop("id").split("_");
if("user_name" == user_match[0] && "user_type" == user_match[2]){
// I'd like to return user_name John and user_type Admin here
}
});
I've use .first()
, but still not get the desired output.
Current exact script used:
$(".isBilling").each(function(i){
var input_type = $(this)[0].tagName;
var company_match = $(this).prop("id").split("_");
if(input_type == "SELECT"){
var val_billing_addr = $(this).find("option:selected").text();
}
else{
var val_billing_addr = $(this).val();
}
$(".billing").each(function(i){
var billing_match = $(this).first().prop("id").split("_");
var default_addr = company_match[0] + "_" + company_match[2] + "_" + company_match[3];
var billing_addr = billing_match[0] + "_" + billing_match[2] + "_" + billing_match[3];
if(default_addr == billing_addr){
$(this).val(val_billing_addr);
}
});
});