본문 바로가기

JavaScript47

[javascript][event] Detect mouse right click: context menu Is right click a Javascript event? Search: how to detect mouse right click in javascript window.oncontextmenu = function () { alert('Right Click') } $("#myId").mousedown(function(ev){ if(ev.which == 3) { alert("Right mouse button clicked on element with id myId"); } }); javascript detect right click Code Example document.body.onclick = function (e) { var isRightMB; e = e || window.event; if ("wh.. 2022. 7. 5.
[BST] Construct binary search tree methods :: insert, contains, remove(delete) BST definition BST class BST { constructor(value) { this.value = value; this.left = null; this.right = null; } insert(value) { let currentNode = this; while (currentNode !== null) { if (currentNode.value > value) { if (currentNode.left === null) { currentNode.left = new BST(value); } else { currentNode.left.insert(value); } } else { if (currentNode.right === null) { currentNode.right = new BST(v.. 2022. 7. 4.
CSS selector with data attribute [css] selector [attributes=”—”], data attributes with data attribute div[data-your-name="tio"] { } with javascript dom manipulation const dom = document.querySelector('div.test[data-id="100"]'); General usage [class="(╯°□°)╯︵ ┻━┻"]{ color: red; font-weight: bold; } [data-value] { /* Attribute exists */ } [data-value="foo"] { /* Attribute has this exact value */ } [data-value*="foo"] { /*.. 2022. 7. 4.
requestFullscreen(): How to make dom Fullscreen [Document.fullscreenElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenElement) / [ShadowRoot.fullscreenElement](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/fullscreenElement) The fullscreenElement property tells you the [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) that's currently being displayed in fullscreen mode on the DOM (or .. 2022. 7. 2.
Keyboard Event: How to detect keyboard you typed: e.which, e.keycode, e.key, e.charcode, e.code which, keycode, key, charcode, code when I type 'f', charCode: 0 keyCode: 70 key='f' code='KeyF' which: 102 charCode, keyCode: deprecated charCode: Non-standard Reference 2022. 6. 29.
Event vs CustomEvent && How to trigger event with data Event vs CustomEvent CustomEvent can send data through 'detail' property, but Event can not do that; Event const eventInstance = new Event(':eventName'); // add event on document document.addEventListener(':eventName', (e) => { // TODO console.log(e); }); // trigger event document.dispatch(eventInstance);CustomEvent const customEventInstance = new CustomEvent(':custom.. 2022. 6. 27.
Constructor overloading with default 변수 선언 후 생성자에서 할당 class Test { name: string; protected age: number; public id?: string; private password?: string; constructor(name = "", age = 0, id = undefined, password = undefined) { this.name = name; this.age = age; this.id = id; this.password = password; } }생성자에서 선언하고 변수 할당하기 => id, password class Test { name: string; protected age: number; constructor( name: string = "", age: number = 0, p.. 2022. 6. 25.