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

  • Home
  • SEARCH
  • 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 204911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:30:35+00:00 2026-05-11T17:30:35+00:00

I use html attribute title to set some hints like this: <a href… title=Go

  • 0

I use html attribute title to set some hints like this:

 <a href... title="Go to next chapter">Go</a>

Then the jquery plugin goes through all the [title] attributes and makes pretty tooltips. Very simplified a new div is created for the link above

<div style="position:absolute...">Go to next chapter</div>

The problem is, that the title is editable by user, so he can write whatever he wants. I first thought that html encoding is fine, but it turned out that I was wrong.
If I have

<a id="a" title="&lt;script&gt;alert(10);&lt;/script&gt">Go</a>

then the tooltip div looks like this:

<div style="position:absolute..."><script>alert(10)</script></div>

1) Why browser decodes the title attribute when querying its value?

2) And how can I solve it? (I know that one solution is double html encoding, but it’s awfull)

How to test it: consider this code

<html>  
 <body>  
  <!-- encoding once, this doesn't work -->
  <a id="a" title="&lt;script&gt;alert(10);&lt;/script&gt">atitle</a>  
  <!-- encoding twice, this works -->
  <a id="b" title="&amp;lt;script&amp;gt;alert(10);&amp;lt;/script&amp;gt">btitle</a>  

  <script>  
   function w(x){ document.write(x.attributes["title"].value);}  
   w(a);  // shows alert
   w(b);  // outputs it correctly into the page
  </script>  
 </body>  
</html>
  • 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-11T17:30:35+00:00Added an answer on May 11, 2026 at 5:30 pm

    1) The attribute value is the decoded value – it’s the only way that makes sense if you think about it. If you set a javascript value to “\n” then alert it, do you want to get back “\n” or a real newline? The title attribute is text… you just happen to have to HTML-encode it to write it.

    2) You could double-encode it, or you could use a text node:

    var node = document.createTextNode(x.attributes['title'].value);
    document.appendChild(node);
    

    This is the preferred way, then spiders / non-javascript browsers will see the correct title attribute.

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

Sidebar

Ask A Question

Stats

  • Questions 132k
  • Answers 132k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are your goals performance, maintainability, improving the odds of success,… May 12, 2026 at 6:31 am
  • Editorial Team
    Editorial Team added an answer You'll need to use the CollectionDataContract attribute to handle this… May 12, 2026 at 6:31 am
  • Editorial Team
    Editorial Team added an answer You can use sys.exit() to tell that the program exited… May 12, 2026 at 6:31 am

Related Questions

I use html attribute title to set some hints like this: <a href... title=Go
This is a kind of a random thing I need. Basically my setup is
The demos for the jquery ui dialog all use the flora theme. I wanted
I am trying to pull at list of resource/database names and IDs from a
In a DTO object I'd like to hard code the label description for the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.