How to iterate through children of a node and modify them?

How to iterate through children of a node and modify them?

I have an tag of type 'article' in my html page.  I want to iterate though all its child and grandchild nodes, and give them an ID if they lack one.

So I tried this code as a test:
  1.  $(document).ready(function () {
  2.             $("#ArticleToHighlightRFS").find("*").each(function (i) {
  3.                 alert (this.id); 
  4.             });
  5.         })
The idea is that 'find()' would get all descendant nodes that are not text nodes, and would list their ids.  If they don't have ids, I suppose the alert box would show 'undefined'.  
The above works, but I have to be able to also:
1) note if the element is self-ending, like the linebreak (br) tag.  In that case, setting an ID might be a syntax error.
2)  set an id if the id is 'undefined'
Any help is appreciated.
Thanks.