javascript - js - check if same class elements have id -
i have 2 input tags:
<input type="text" class="maintext" id="input"> <input type="text" class="maintext">
i need set id input tag don't have id, may jquery like:
if(input tag has no id){ $(".maintext").attr("id", "someinput"); }
how find non id input?
use magic of jquery selectors:
$('.maintext:not([id])').prop('id', 'someinput');
it select elements .maintext
class :not
have attribute [id]
.
Comments
Post a Comment