LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 05-27-2024, 02:25 AM   #1
MakeTopSite
Member
 
Registered: Jan 2021
Location: EU
Distribution: Ubuntu, openSUSE Leap & TW, Devuan, Debian
Posts: 354

Rep: Reputation: 4
How set HTML element title by JS function ?


How can I please make something like that:
Code:
<p title=<script>SomeJSFunctionReturningString();</script> 
...
/p>
 
Old 05-27-2024, 05:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,923
Blog Entries: 1

Rep: Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885
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.
Old 05-28-2024, 12:10 AM   #3
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,639
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
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.
Old 06-09-2024, 05:13 AM   #4
MakeTopSite
Member
 
Registered: Jan 2021
Location: EU
Distribution: Ubuntu, openSUSE Leap & TW, Devuan, Debian
Posts: 354

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Konsole tab title is PWD, Gnome Terminal tab title includes hostname...how to change? L_Carver Linux - Newbie 4 05-07-2017 01:50 AM
[SOLVED] Terminal xterm Title is too dynamic (title doesn't change manually) ZeroDaHero Slackware 4 11-04-2012 12:16 PM
Can't call method "title" on undefined title in Perl script scuzzman Programming 12 12-11-2009 04:40 AM
under with title and sub title the "GTK devel" found in fc3? AKAKAK Fedora 3 02-27-2005 05:51 AM
HTML setting focus on a form element on load patpawlowski Programming 3 02-24-2004 10:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration