SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cannot figure a way past around .update() in Prototype

    Hi

    Im trying to port a script from Prototype to jQuery and I've run into a line that is impossible for me to get working. Here is the function:

    Code:
    function createAnchorNode(textLocation, tln, lemma) {	
    
      
      // split the anchor node up to create the new note anchor
      var lemmaMatch = textLocation.nodeValue.match(lemma);  
      var restOfString = textLocation.splitText(lemmaMatch.index); 
      restOfString.deleteData(0, lemma.length);
      var note = jQuery(document.createElement('span')).addClass('noteAnchor').get(0);
      // PROBLEM AREA
      note = $(note).update(lemmaMatch);
      //note = jQuery(note).text(lemmaMatch).get(0); 
      // END PROBLEM AREA
      textLocation.parentNode.insertBefore(note, textLocation.nextSibling);
      textLocation.parentNode.insertBefore(restOfString, note.nextSibling);
      return note;
    }
    I want to erase the line starting with $, and replace it with the commented out line.

    This is what the source code looks like when Prototype does it right:
    Code:
    <div class="ln tln" id="tln7" name="tln7">
         <!---->
    </div>
    <span class="noteAnchor">on his blessing</span>, to 
    <span class="noteAnchor">breed me well</span>; and 
    <div class="ln tln" id="tln8" name="tln8">
         <!---->
    </div>
    And this is what happens when, jQuery is used:
    Code:
     <div class="ln tln" id="tln7" name="tln7">
         <!---->
     </div>, to ; and 
     <div class="ln tln" id="tln8" name="tln8">
         <!---->
     </div>there begins my sadness.  Jaques he keeps
    Basically, all i want is to create a span element with a class name of noteAnchor, and give it the text contents stored in lemmaMatch (lemmaMatch is a RegExp object). I even tried to do this in native javascript using
    Code:
    note.firstChild.nodeValue = lemmaMatch
    but no dice. This is driving me nuts. Can anybody offer some help?

  2. #2
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for example, even this doesn't work the same as that single Prototype .update() function:

    Code:
    function createAnchorNode(textLocation, tln, lemma) {	
    
      
      // split the anchor node up to create the new note anchor
      var lemmaMatch = textLocation.nodeValue.match(lemma);  
      var restOfString = textLocation.splitText(lemmaMatch.index); 
      restOfString.deleteData(0, lemma.length);
      //var note = jQuery(document.createElement('span')).addClass('noteAnchor').get(0);
      // PROBLEM AREA
      //note = $(note).update(lemmaMatch);
      //note = jQuery(note).text(lemmaMatch).get(0); 
      // END PROBLEM AREA
      
      var note = document.createElement('span');
    	elem.setAttribute("class", "noteAnchor");
    	var text = document.createTextNode(lemmaMatch.toString());
    	elem.appendChild(text);
    	
      
      textLocation.parentNode.insertBefore(note, textLocation.nextSibling);
      textLocation.parentNode.insertBefore(restOfString, note.nextSibling);
      return note;
    }
    what is going on....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •