1

I have a simple coffeescript to process a specific selector (part_ids) ..

 alert "Starting  blines  " + $("[id*=part_id]").length
 for bl in $("[id*=part_id]")
   do(bl) ->
     procBl bl

  procBl  = (bl)  ->
     alert "# of children "  + bl.children().length

First alert show 2 items are on the page. For loop runs -- however the procBl doesn't print the alert (it quietly exits) It appears that bl that's being iterated and passed to the function is not the correct object and I can't figure out what's it and wrong with this code -

any help is appreciated

1 Answer 1

1

bl passed into procBl function is not a jQuery instance, but plain DOM element. Wrap it with $() to use children method:

  procBl  = (bl)  ->
     alert "# of children "  + $(bl).children().length

... or use $.fn.each method to iterate over $("[id*=part_id]") collection.

Sign up to request clarification or add additional context in comments.

3 Comments

dfsq -- wrapping with $ works in the for loop but doesn't work in the function -- it exits quietly -- could you show me the syntax for using the .each -- on the collection .. thanks .. the
$("[id*=part_id]").each -> alert "# of children " + $(this).children().length;
Thanks .. as I said it works in the for loop .. but I still can't call the function with bl or $(bl) :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.