Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-27-2024, 02:25 AM
|
#1
|
Member
Registered: Jan 2021
Location: EU
Distribution: Ubuntu, openSUSE Leap & TW, Devuan, Debian
Posts: 354
Rep:
|
How set HTML element title by JS function ?
How can I please make something like that:
Code:
<p title=<script>SomeJSFunctionReturningString();</script>
...
/p>
|
|
|
05-27-2024, 05:11 AM
|
#2
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,923
|
That doesn't work this way. Try some action-handler attribute like onmouseover:
Code:
<script>function setTitleTo(elem,value) {
elem.title= value;
}</script>
...
<p title="default" onmouseover="setTitleTo(this,'Sometext')" onmouseout="setTitleTo(this,'Othertext')"
|
|
1 members found this post helpful.
|
05-28-2024, 12:10 AM
|
#3
|
Senior Member
Registered: Dec 2015
Posts: 1,639
Rep:
|
Quote:
Originally Posted by NevemTeve
That doesn't work this way. Try some action-handler attribute like onmouseover:
Code:
<script>function setTitleTo(elem,value) {
elem.title= value;
}</script>
...
<p title="default" onmouseover="setTitleTo(this,'Sometext')" onmouseout="setTitleTo(this,'Othertext')"
|
That is it.
Or, if the procedure is only meant to spare you the trouble to set titles based on given properties of an element, call the script in an onload-handler (i.e. upon page load). In this cas you have to identify the interesting properties of the element in question inside the script or determine them from parameters or both (probably both).
Keep reading the docs.
|
|
1 members found this post helpful.
|
06-09-2024, 05:13 AM
|
#4
|
Member
Registered: Jan 2021
Location: EU
Distribution: Ubuntu, openSUSE Leap & TW, Devuan, Debian
Posts: 354
Original Poster
Rep:
|
Quote:
Originally Posted by NevemTeve
That doesn't work this way. Try some action-handler attribute like onmouseover:
Code:
<script>function setTitleTo(elem,value) {
elem.title= value;
}</script>
...
<p title="default" onmouseover="setTitleTo(this,'Sometext')" onmouseout="setTitleTo(this,'Othertext')"
|
Thank you this has solved the problem.
|
|
|
All times are GMT -5. The time now is 01:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|