SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remove All title="" Attributes

    I've searched extensively for this.

    Unfortunately after trying many solutions nothing has yet to work.

    I'm looking for a JavaScript (not jQuery) that will seek and destroy any and all a link title tags and take absolute precedence over any other scripts/functions.

    Thanks, Bryan

  2. #2
    SitePoint Evangelist TommiChi's Avatar
    Join Date
    Oct 2008
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this should work:
    var links = documentgetElementsByTagName('a');

    var i = 0, iMax = links.length;

    while(i < iMax) {
    var parentElem = links[i].parentNode;
    parentElem.removeChild(links[i]);
    }
    i++;
    }

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by TommiChi View Post
    Something like this should work:
    var links = documentgetElementsByTagName('a');

    var i = 0, iMax = links.length;

    while(i < iMax) {
    var parentElem = links[i].parentNode;
    parentElem.removeChild(links[i]);
    }
    i++;
    }
    That would delete all the <a> tags and their content and not just title attributes. (or it would if it had a dot after document in the first line and didn't have an extra } in the middle of the loop).

    Try:

    Code:
    var links = document.getElementsByTagName('a');
    var i = links.length;
    while (0 < i) links[--i].title = '';
    Last edited by felgall; Feb 2, 2011 at 13:46.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried yours and I also tried:

    Code JavaScript:
    var links = document.getElementsByTagName('a');
    var i = links.length;
    while (0 < i) links[--i].title="";

    No go. Perhaps it needs to be set to execute only after the page has loaded?

    Thanks, Bryan

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by calmestghost View Post
    Perhaps it needs to be set to execute only after the page has loaded?
    Yes. You can't update the content of a web page from JavaScript until after that content has loaded. (That's why it is now common to add the script tag immediately before the </body> so that the page loads first).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Okay, it's in place now.

    I think it's conflicting with another script. Is there any way to command precedence with JS like you would use the
    Code CSS:
    !important
    deceleration with CSS?

    Thanks, Bryan

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by calmestghost View Post
    Thanks. Okay, it's in place now.

    I think it's conflicting with another script. Is there any way to command precedence with JS like you would use the
    Code CSS:
    !important
    deceleration with CSS?

    Thanks, Bryan
    That's controlled by the order the scripts run in. Whichever script runs last wins.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, that's what I always assumed.

    Maybe the JS syntax needs to be able to handle the way these links are setup then, example link:

    Code JavaScript:
    <a title="FAQs" href="faqs.php"><span style="">FAQs</span></a>

    As you can see it throws the title right after a. Ideally, the best fix would be to stop the function that's auto adding titles in the first place only it's obviously deep in the core code or in one of thousands of files.

    I've searched for hours for that answer to no avail so I'm now trying to cover up / workaround the problem.

    Thanks, Bryan

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by calmestghost View Post
    I've searched for hours for that answer to no avail so I'm now trying to cover up / workaround the problem.
    More eyes makes problems more transparent.

    Link us through to a test version of the page, and we'll quickly find out what's causing that to happen.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •