jQuery assertion support / defensive programming?

前端 未结 4 458
臣服心动
臣服心动 2021-02-07 05:50

Is there any built in support in jQuery for basic assertion checking, primarily of things like \'expected number of returned elements\'.

For instance I may have a simple

4条回答
  •  清酒与你
    2021-02-07 06:31

    You probably want http://docs.jquery.com/Traversing/eq#index:

    Reduce the set of matched elements to a single element.

    If your selector returns no objects then jQuery simply won't run the chained code as it has no elements to run them on

提交回复
热议问题