Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: InnerText?

  1. #1
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts

    InnerText?

    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.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #2
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, there is an innerText property but it's IE-only.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #3
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, thanks.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #4
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #6
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's my function:
    Code:
    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.)
    Code:
    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;
    }
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, cool. Nice job.

    I'll have to look around for that other script cheesebag made... I'm almost positive he made something like that.

    Good luck.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #8
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, help appreciated
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #9
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure if this is exactly what you're looking for, but check this thread out. That's the one I was thinking of.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #10
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!


  •  

    Posting Permissions

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