开发者

jquery find command

开发者 https://www.devze.com 2023-01-17 23:03 出处:网络
Using .find() 开发者_运维百科how to find whether radio button exists in a div or else raise an alert

Using .find() 开发者_运维百科how to find whether radio button exists in a div or else raise an alert

          <div id="emp_form">

          </div>


You can use .find() (or just a descendant selector) and check the .length like this:

if($("#emp_form :radio").length == 0) {
  alert("No radio buttons found!, Crap!");
}

Of if you want to do something in the case there are radio buttons:

if($("#emp_form :radio").length > 0) {
  //do something
} else {
  alert("No radio buttons found!, Crap!");
}

The .find() alternative is $("#emp_form").find(":radio").length.


Try this -

if ($('#emp_form :radio').length != 0) {
    alert('exists');
  } else {
    alert('does not exist');
  }


if ( $("#emp_form").find("input[type='radio']").length >0 ) {

} else {
   alert("There is nothing");
}

Fixed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号