Old 11-04-2007, 14:24   #1 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
regex javascript?

Anyone know how to get the text between a div when the div has a specific class?

such as

<div class="crazy">
Paul
</div>

I want the regex to return "Paul" I cant find any patterns that work.
__________________
  Reply With Quote
Old 11-04-2007, 14:39   #2 (permalink)
funkyprem
For all your goober needs
 
funkyprem's Avatar
 
Join Date: Dec 2004
Location: Coventry, UK
Posts: 1,468
don't have the code to hand, but it's getElementsByClass you need to look up then once that's created an 'object' you get the innerHTML of it.
__________________
Time is really the only capital that any human being has, and the one thing that he can’t afford to lose. - Thomas Edison

prem ghinde
  Reply With Quote
Old 12-04-2007, 02:08   #3 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
ah.. good stuff.
__________________
  Reply With Quote
Old 12-04-2007, 16:36   #4 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
sorry guys needa bump this again . getElementByClass only works with the current document, I need it to work with a variable.
__________________
  Reply With Quote
Old 12-04-2007, 21:19   #5 (permalink)
gk
geek
 
gk's Avatar
 
Join Date: Oct 2006
Location: *.everywhere
Posts: 204
Send a message via ICQ to gk Send a message via AIM to gk Send a message via MSN to gk Send a message via Yahoo to gk
I've never use regexp in javascript so i dont know if there is a variation in the syntax but well quick and dirty...

Code:
/class="crazy".*?>([^<]*)/

should work so long as there are no html tags inside the div.

the other way you could cheat by creating a hidden div with javascript write your variable to the div then use getElementByClass... I think that could work
  Reply With Quote
Old 13-04-2007, 07:38   #6 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,130
I'd append the variable to a hidden element and use getElementByClass on it myself.
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Old 13-04-2007, 07:39   #7 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,130
Though I'd probably be using jquery so wouldn't need to use getElementByAnything anyway.

Might help if you told us what you're trying to do rather than the problem you're having, more than likely a better way to do it than regex on a variable.
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Old 13-04-2007, 15:07   #8 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
fair enough. I'm trying to screenscrape using javascript. I have the page I need in a variable (the pure html contents), now I need to extract an image from between a div class...should be simple enough. Why client side? cause I want to. This hidden variable malarchy sounds rather dirty, especially after looking at getElementsbyClass as a function in its own right.
__________________
  Reply With Quote
Old 16-04-2007, 08:50   #9 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,130
Append the contents to a hidden div and use the dom to find the bit you need.
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8