View Single Post
Old 07-18-2011, 12:22 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
scraping can be tricky, especially with text segments.
i often use my handy node getter for these types of situations.

indeed, it seemed to work like a charm on the markup you posted:

Code:
<body>
 <div style="display: none;" id="questiondiv">
You challenge The Wiseman to a game of trivia, he asks you this question:<br/>&nbsp;<br/>
               <!--store from here-->What did David Stirling find?<!--to here in a var--> (Hint: S__)<br/>&nbsp;<br/>
                <input class="dungeoninput" type="text" size="16" id="answer" value="" maxlength="32"></input><br/>
                <div class="btn100" style="margin-top: 6px;"
				onclick="loadDiv2('/dream/explore?action=acceptTrivia&qid=727'); return false;">Answer</div>
                </div>









<script>
function getNodes(prop, val, meth, nd, useSelf ){
 var r=[], any= getNodes[val]===true;
 nd=nd||document.documentElement;
 if(nd.constructor===Array){nd={childNodes:nd};}
  for(var cn=nd.childNodes, i=0, mx=cn.length;i<mx;i++){
    var it=cn[i];
    if( it.childNodes.length && !useSelf ){r=r.concat(getNodes(prop, val, meth, it,useSelf ));}
	if( any ? it[prop] : (it[prop]!==undefined && (meth ? ""[meth] && 
		String(it[prop])[meth](val) : it[prop]==val))){
		  r[r.length]=it; 
	}
  }//nxt
 
return r;
};getNodes[null]=true;getNodes[undefined]=true;
//end getNodes()






//example: 	(modify arguments to suit your needs)
alert(
  getNodes(
	"data",	//examine each node's .data property (only hits text nodes)
	/\?/,		//looking for text with a "?"
	"match",	//using String().match method to accept arguments[1]
	document.getElementById("questiondiv") // looking in the question div
  )[0].textContent 	//show text of first match
);



</script>
</body>
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote