Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

transform getElementById to work with class

Featured Replies

Hello,

I know nothing about javascript. And I have this script:

 

<script type='text/javascript'>
  window.onload = function() {
        para = document.getElementById('my_id').getElementsByTagName('a');
      if(para.length)
          for(index in para){
              para[index].removeAttribute('title');
          }
  }
 </script>

 

I need it to work by "class" and not "id".

Could someone rewrite it for me? :D

Include that script, and afterwords use this.

 

Should theoretically work.

 

 

<script type='text/javascript'>
  window.onload = function() {
        para = document.getElementsByClassName('my_class').getElementsByTagName('a');
      if(para.length)
          for(index in para){
              para[index].removeAttribute('title');
          }
  }
 </script>

 

  • Author

Fail...

I downloaded the script "ByClassName" on this link: http://code.google.com/p/getelementsbyclassname/downloads/list.

 

My html:

 

<html>
<head><title>Title of hell</title>
<script src="getElementsByClassName-1.0.1.js" type="text/javascript"></script>
<script type='text/javascript'>
  window.onload = function() {
        para = document.getElementsByClassName('my_class').getElementsByTagName('a');
      if(para.length)
          for(index in para){
              para[index].removeAttribute('title');
          }
  }
 </script>

</head>
<body>
<ul class="my_class">
	<li><a title="Title of hell" href="#">Title of hell</a>
</ul>
</body>
</html>

Try adding the class="my_class" to the <li> or to the <a>.

  • Author

Still not working ...

 

Just to clarify.

This script removes the title attribute to all tags <a> contained in all elements with "id" mentioned.

 

I did what I asked. But I need it to act in <ul>. Because it works with the getElementById in <ul>.

  • Author

Use jQuery - problem solved.

 

But I need a solution that does not use libraries ...

 

I am a layman in JS. But I believe that this is not to be so complicated for experienced users.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.