This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Check if html th is on focus
#1
I want to find out wether my HTML Event is on focus (not if it is clicked but focused by navigating with the keyboard).
myElement === document.activeElement
is only true when the element is clicked but not when it's focused by keyboard navigation.
    tooltip(){
  var myElement = document.getElementById("myID");
  let myEvent = "";
  if (myElement=== document.activeElement){
     myEvent = "focus";
  }

return myEvent;
};



<th id="myID" *ngSwitchCase="'validation'" tooltipEvent={{tooltip()}} pTooltip="I am a tooltip"
          tooltipPosition="top" [escape]="false"   [pSortableColumn]="column.field" [ngStyle]="column.style">
            <div class="col-title">
            <span data-testid="column-validationl-header" class="ui-column-title" >Validation </span>
              <p-sortIcon [field]="column.field" *ngIf="column.sortable"></p-sortIcon>
            </div>
          </th>
any Ideas?
Zitieren
#2
Hi opti13403,
this Forum is a German Forum. Please write in German in the future in this forum. I have a suitable solution for your problem. I hope it helps you.

'use strict';
document.addEventListener('DOMContentLoaded', init);
var elem, isfocus;
function init() {
    isfocus = false;
    elem = elem = document.getElementById("myID");
    elem.addEventListener('focus', function() {
        isfocus = true;
    });
    elem.addEventListener('blur', function() {
        isfocus = false;
    });
}

In this case i use two different event-handler. One to trigger on an focus-event and one for the blur-event. Your code is buggy and it is not written in the HTML or in the HTML5-Standard. TH as element stands for tablehead and is an part of a table.
p-sortIcon
This is not an element in HTML or HTML5. The p-element stands for paragraph.
Zitat:[font=Consolas, "Courier New", monospace]<p class="sortIcon" data-field="column.field" data-ngIf="column.sortable"></p>[/font]


bw rzscout

"Gerne dürft ihr mir eine gute Bewertung da lassen aber auch gegenüber Kritik bin ich offen" Angel
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste