vibog vibog - 5 months ago 12
CSS Question

How we can compere or check input filed type of html element with jquery

Hi I am working on jquery and I am trying alert for check div's child field type . I mean check that is input field and having which type . please see my small code :

if($('#'+Gid).find("input[type=radio]"))
alert("radio");
if($('#'+Gid).find("input[type=checkbox]"))
alert("radio");
if($('#'+Gid).find("select"))
alert("select");


If any field is present in div that can alert for that . Right now that is going in every condition . Please anyone help me for that . Thanks

Answer

Please check

var Gid = "container";

if($('#'+Gid + " > input[type=radio]").length > 0)
    console.log("Radio");
if($('#'+Gid + " > input[type=checkbox]").length > 0)
    console.log("Checkbox");
if($('#'+Gid + " > select").length > 0)
    console.log("Select");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<input type="radio" />  
  <input type="checkbox" />  
 <select></select>
</div>

Comments