angularjs - Trigger click programatically on a single element of a list in Angular/JavaScript -


i writing test want click on second item in list , check has changed.

i have bullet list element:

<ul>     <li>item 1</li>     <li>item 2</li>     <li>item 3</li> </ul> 

i have tried following (element angular element containing entire list):

var li = element.find('li');  li.triggerhandler('click'); //clicks elements li[1].triggerhandler('click'); //error: li[1].triggerhandler not function 

none of these works. first attempt clicks items , second throws error.

any ideas how trigger click on second item?

triggerhandler works on jquery (or builtin jqlite) elements. element.find returns jquery element (li) li[1] is dom node, not jquery wrapped element. use element.find('li:eq(1)') (if use jquery) or element.find('li').eq(1) (with builtin jqlite) instead.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -