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 7688453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:55:27+00:00 2026-05-31T19:55:27+00:00

I appologize I am not very versed in Javascript and jquery but what I

  • 0

I appologize I am not very versed in Javascript and jquery but what I need to do is find a span with a certain title “Title1” and add a class to that span. I tried several different methods just looking at examples I found by googling but nothing has worked. Anybody got a good example on how to do this. Below is what I think should work?

$('span[@title="Title1"]').each(function(){ 
var $this = $(this); 
// attach the Padding Class
$this.addClass("paddingleft4");
} 
); 

Any help would be appreciated

  • 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-31T19:55:28+00:00Added an answer on May 31, 2026 at 7:55 pm

    First of all, there are several different ways to try what you’re doing, however I wouldn’t recommend find elements by title. Title’s are generally meant to hold a string containing information pertinent to the user when they mouse over the element. It would be far better to add a class to your spans before run-time and then search for those spans based on that pre-established class.

    Of course, the simplest method is already shown:

    $('span[title="Title1"]').addClass('paddingleft4');
    

    However, you could also use a million different possiblities with jQuery’s .filter() function.

    As seen on this jsFiddle, I make use of .filter by changing the text of spans that don’t have Title1 inthere title string.

    After just reading your comment on your question, I thought i should mention some things in easy commented format:

    <script type="text/javascript">
        // jquery equivilant to window.onload = function() { /* do work */ }
        // also = to jQuery's own #(document).ready(function() { /* do work */ })
        $(function() {
    
            $('span')   //  this is simple jquery call to create an object of all spans on document
            .filter(function(i) {   //  this tells jQuery to take those spans and filter out the ones that dont get returned on the inner function
                //  this is that function
                //  here i use it to see if the spans title
                //      contains the phrase "1L - Students"
                //      if not, then false is return and that
                //      item is removed from our initial jQuery object
                return $(this).attr("title") ? $(this).attr("title").indexOf("1L - Students") != -1 : false;
            })
            .each(function(i) { //  this .each is being used because i'm replace the TEXT of each span left in object with its TITLE string
                $(this).text($(this).attr("title"))
            });
        })
    </script>
    

    if span is created dynamically, maybe try placing script at end of body (see comments)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not very familiar with regEx's and I'm trying to find a preg_match regex
Before I start, I apologize for a bad title but I could not come
I am not very good at regex, and frankly find it difficult to wrap
I apologize for not knowing xsl very well, but i have an xml document
First of all, I have to apologize for not having a better title. Feel
I apologize if the question is trivial, but some googling is not leading me
i apologize in advance for not being very precise, as a i dont know
I apologize if this is a duplicate post, but I couldn't find the answer
I am searching for the part of the webpage that goes: <TR class='title'><TD colspan=3
I apologize if this is a really beginner question, but I have not worked

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.