Sunday, 11 August 2013

Stopping the Jquery.map when a condition is met

Stopping the Jquery.map when a condition is met

I have the following code:
var parentEls = node.parents()
.map(function () {
var curParentID = this.getAttribute("id");
var curParentClass = this.getAttribute("class");
if(curParentID)
return this.tagName + "#" + curParentID;
/*stop the map function from proceeding*/
else
return this.tagName;
})
.get().reverse().join(", ");
The above code helps to find search for unique id and once an ID is
spotted , it creates the xpath. How can i stop the the map function once
it has come to a point where the id is retrieved and the map function
should stop? I tried return false and break but it does not work.
Is there any other suggestion?

No comments:

Post a Comment