Results 1 to 3 of 3

Thread: How set HTML element title by JS function ?

  1. #1
    Join Date
    Sep 2019
    Beans
    226

    How set HTML element title by JS function ?

    How can I please make something like that:
    Code:
    <p title=<script>SomeJSFunctionReturningString();</script> 
    ...
    /p>

  2. #2
    Join Date
    Jun 2016
    Beans
    2,864
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: How set HTML element title by JS function ?

    Is this for your own webpage, or are you writing a user script?
    Could you please explain more details of what you're trying to achieve with setting title attribute by script?

    The answer will involve
    Code:
    .setAttribute('title', SomeJSFunctionReturningString());
    But that is a very incomplete Javascript code snippet that isn't enough to work. The rest depends what you're trying to do, when & how often you want the title updated.
    Xubuntu 22.04, ArchLinux ♦ System76 hardware, virt-manager/KVM, VirtualBox
    If your questions are resolved to your satisfaction, please use Thread Tools > "Mark this thread as solved..."

  3. #3
    Join Date
    Sep 2019
    Beans
    226

    Re: How set HTML element title by JS function ?

    Quote Originally Posted by halogen2 View Post
    Is this for your own webpage, or are you writing a user script?
    Could you please explain more details of what you're trying to achieve with setting title attribute by script?

    The answer will involve
    Code:
    .setAttribute('title', SomeJSFunctionReturningString());
    But that is a very incomplete Javascript code snippet that isn't enough to work. The rest depends what you're trying to do, when & how often you want the title updated.
    It's a user script for some webpage.

    I need show some text (Tooltip) any time mouse hover over some text.

    Solution:
    Code:
    <script>function setTitleTo(elem,value) {
        elem.title= value;
    }</script>
    ...
    <p title="default" onmouseover="setTitleTo(this,'Sometext')" onmouseout="setTitleTo(this,'Othertext')"
    source:

    https://www.linuxquestions.org/quest...6/#post6504045

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •