I've 'grabbed' an element using getElementById, now I want to find the text that's inside that element.
I could use innerHTML, but at the moment that returns "<a href="#"> Sample Link </a>" and I'd have to write some kind of parsing program to just get 'Sample Link'.
If there's no property like this, please just tell me, I enjoy the challenge of trying to write programs myself and I'd like to create the parser myself.
fredmv 10-03-2003, 05:32 PM Well, there is an innerText (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/innertext.asp) property but it's IE-only.
Ok, I've written a parser and it works fine, but one more question.
Is there any way, when we have a block of text, to find out how many pixels it is wide on the users screen?
It sounds nice and complicated, so I thought I'd ask before having a go.
fredmv 10-03-2003, 08:09 PM Originally posted by me'
Is there any way, when we have a block of text, to find out how many pixels it is wide on the users screen?
By default, I don't think so... But search around here. Good ole' cheesebag put together a custom script that did something like that I believe.
Also, if you wouldn't mind, could we check out your script for getting the text inside an element? :D
Here's my function:
function foo() {
lefts = getElementsByClass('left','e');
alert(lefts[0].innerHTML);
var s='', t='', intag;
for (var i=0; i<lefts.length; i++) {
s = lefts[i].innerHTML;
for (var j=0; j<s.length; j++){
if (s[j] == '<') intag = true;
if (!intag) t += s[j];
if (s[j] == '>') intag = false;
}
alert(t); //Will change this to something more useful eventually
t='';
}
}
This is the getElementsByClass function that you'll also need (posted by cheesebag on my thread 'getElementById for classes?' a while back. Do a search.)
function getElementsByClass( _class, el_id )
{
var parent, els, returnArr = new Array(), i = 0;
parent = (el_id) ? document.getElementById(el_id) : document;
els = parent.getElementsByTagName('*') || parent.all;
for (i; i < els.length; i++)
if (els[i].className == _class)
returnArr[returnArr.length] = els[i];
return returnArr;
}
fredmv 10-03-2003, 08:17 PM Alright, cool. Nice job. :thumbsup:
I'll have to look around for that other script cheesebag made... I'm almost positive he made something like that.
Good luck.
Thanks, help appreciated :)
fredmv 10-03-2003, 08:56 PM I'm not sure if this is exactly what you're looking for, but check this thread (http://www.codingforums.com/showthread.php?s=&threadid=26689) out. That's the one I was thinking of.
Well, that'll return a space, but I didn't think of reading the offsetWidth... heh...
I'll do that and minus the padding etc.
Well, thanks for the help.
|
|