Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:05:28+00:00 2026-05-15T08:05:28+00:00

I have system-generated links which I hide manually. Now I want to remove the

  • 0

I have system-generated links which I hide manually. Now I want to remove the link’s title attributes sicne those are copied when the user copies surrounding text.

<html>
<head>
<script type="text/javascript">

    var getElementsByClassName = function (className, tag, elm){
    if (document.getElementsByClassName) {
        getElementsByClassName = function (className, tag, elm) {
            elm = elm || document;
            var elements = elm.getElementsByClassName(className),
                nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                returnElements = [],
                current;
            for(var i=0, il=elements.length; i<il; i+=1){
                current = elements[i];
                if(!nodeName || nodeName.test(current.nodeName)) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    else if (document.evaluate) {
        getElementsByClassName = function (className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = "",
                xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
                returnElements = [],
                elements,
                node;
            for(var j=0, jl=classes.length; j<jl; j+=1){
                classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
            }
            try {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
            }
            catch (e) {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
            }
            while ((node = elements.iterateNext())) {
                returnElements.push(node);
            }
            return returnElements;
        };
    }
    else {
        getElementsByClassName = function (className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = [],
                elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
                current,
                returnElements = [],
                match;
            for(var k=0, kl=classes.length; k<kl; k+=1){
                classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
            }
            for(var l=0, ll=elements.length; l<ll; l+=1){
                current = elements[l];
                match = false;
                for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
                    match = classesToCheck[m].test(current.className);
                    if (!match) {
                        break;
                    }
                }
                if (match) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    return getElementsByClassName(className, tag, elm);
};

function notitle() {
  var mylist=document.getElementsByClassName("notitle");
  for (j=0; j<mylist.length; j++) {
    var listitems= mylist[j].getElementsByTagName("a");
    for (i=0; i<listitems.length; i++) {
      listitems[i].removeAttribute("title");
    }
  }
}
</script>
</head>

<body onLoad="notitle()">

<p>Before hidden link 1: <span class="notitle" style="display: none;">
<a href="#Foo" title="Foo">This link should have no title attribute</a>
</span>After hidden link 1.</p>

<p>Before hidden link 2: <span class="notitle" style="display: none;">
<a href="#Foo" title="Foo">This link should have no title attribute</a>
</span>After hidden link 2.</p>

<p>Before hidden link 3: <span class="notitle" style="display: none;">
<a href="#Foo" title="Foo">This link should have no title attribute</a>
</span>After hidden link 3.</p>
</body>
</html>

How should the function look like correctly?
I once got it working using this

function notitle() {
  var mylist=document.getElementById("notitle");
  var listitems= mylist.getElementsByTagName("a");
  for (i=0; i<listitems.length; i++) {
    listitems[i].removeAttribute("title");
  }
}

but that only applied to the first link.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:05:29+00:00Added an answer on May 15, 2026 at 8:05 am

    that is because you should’t give the same id attribute to multiple elements. The id attribute must be unique all over your document. if not it only finds the first element with this id.

    try class="notitle" instead of id="notitle" and you JS should look like this:

    function notitle() {
      var mylist=document.getElementsByClassName("notitle");
      for (j=0; j<mylist.length; j++) {
        var listitems= mylist[j].getElementsByTagName("a");
        for (i=0; i<listitems.length; i++) {
          listitems[i].removeAttribute("title");
        }
      }
    }
    

    As I’ve just learned this would not work cross browser, I would suggest to use a Javascript framework for this kind of propblem, because such a framework is crossbrowser compatible.

    You can add the following script to your website to make it work in all browsers:
    http://code.google.com/p/getelementsbyclassname/downloads/detail?name=getElementsByClassName-1.0.1.js

    It’s far easier if you would use some JavaScript Framework. Here an example for jQuery:

    function notitle() {
      $(".notitle a").removeAttr("title");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++/Rcpp function the I need to compile and link to the
I have an A - Z directory 'widget' that I have on every page.
We began a project using WebForms, and developed a somewhat complex portal system to
I've been tasked to build a system that allows someone in our company to
I know this a is a common issue, but everything I can find in
What is the best way to access a Rails 3 REST-ful web service, developed
Note: The input HTML is trusted; it is not user defined! I'll highlight what
What function in Drupal gets file attachment path? Edit: the attachments provided by Upload
I am documenting a library that has a Python component and a JavaScript component.
What I need to do is capture the result of an expression within an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.