title: Avoid createElement function if it's inside a <LI> element (contentEditable)
body: <p>I'm using this function in order to replace <code>&lt;DIV&gt;New Divs&lt;/DIV&gt;</code> with <code>&lt;BR&gt;</code> in break lines on contentEditable divs using Safari and Chrome:</p>
  
  <pre><code>$("#form_description").live("keypress", function(e){
  if (e.which == 13) {
  if (window.getSelection) {
    var selection = window.getSelection(),
        range = selection.getRangeAt(0),
        br = document.createElement("br");
    range.deleteContents();
    range.insertNode(br);
    range.setStartAfter(br);
    range.setEndAfter(br);
    range.collapse(false);
    selection.removeAllRanges();
    selection.addRange(range);
    return false;
  }
  }
  });
  </code></pre>
  
  <p>The problem is that when I'm typing inside an <code>&lt;UL&gt;&lt;LI&gt;Something&lt;/LI&gt;&lt;/UL&gt;</code> and I press the "return" key, I don't want to get a <code>&lt;BR&gt;</code>, so I can continue whit the list...</p>
  
  <p>How could I create a condition for that function not to work if I'm inside a <code>LI</code> element?</p>
  
  <p><strong>EDIT WITH MY ANSWER:</strong></p>
  
  <p>Ok, I've managed to do it, but If you have any comment on the code, you're welcome:</p>
  
  <pre><code>$("#form_description").live("keypress", function(e){
  if (e.which == 13) {
  
    node = document.getSelection().anchorNode;
    nodeName = node.parentNode.nodeName.toLowerCase();
  
    if ((nodeName != "li") &amp;&amp; (nodeName != "blockquote")) {
  ... etc }
  </code></pre>