selectors-api

How to get the div that has a duplicated id using querySelector()?

随声附和 提交于 2019-12-12 07:28:43
问题 I have a <div> and a <video> that both have the same id: <div id="id1"> Some content </div> <video id="id1"> <source></source> </video> It is not possible for me to change the IDs of the div or the video. The div is created automatically by the video.js library, which gives both the div and the video elements the same id. How do I target the div element alone? (Using querySelector() or similar) 回答1: You can prefix the id name with the element, but don't do this - correct your badly formed

getElementsByTagName does not seem to work

别说谁变了你拦得住时间么 提交于 2019-12-12 03:11:58
问题 Can someone please explain why my code is not working !! When I get the element By Id it works perfectly fine. But the same method with getElementsByTagName() does not. Also if I use querySelector(), it works. However if I use querySelectorAll() the same error returns. test.html:15 Uncaught TypeError: Cannot set property 'color' of undefined here is my code: <DOCTYPE! html> <html> <head> </head> <body> <h1>Hello World</h1> <p id="par">Hello World</p> <script> var par = document.getElementById

querySelector, get elements whose attribute begins with given string

扶醉桌前 提交于 2019-12-12 03:06:57
问题 I'm looking for a way to find all elements that contain an attribute that begins witha a given string. For example: document.querySelectorAll('[ng-*]') would return all elements with Angular directives ( ng-click , ng-show , ng-hide ...). But the wildcard does not seem to work. Any ideas? I could implement my own, but it wouldn't be as effective. 回答1: There's no CSS selector that lets you do wildcards on the name of an attribute, just on the value, which obviously isn't want you want.

get element by classname for IE11

≡放荡痞女 提交于 2019-12-11 19:52:24
问题 I've an issue with queryselectorall and IE11. It works on IE10 and firefox but with last cheet Do you have a solution for having an element by his classname? if(document.querySelectorAll(".classname")) { alert('ici'); document.querySelectorAll(".classname").style.display = "none"; } The alert and display none is working on everything except Internet Explorer 11 thanks 回答1: http://jsfiddle.net/r3XCd/12/ if (typeof document.querySelectorAll !== undefined) { if (document.querySelectorAll("

Displaying clock in div with javascript

自闭症网瘾萝莉.ら 提交于 2019-12-10 11:56:32
问题 I'm getting grey haired here because I can't get this clock to display on my SPA. I'm haveing a clock that should be displayed on the page but I can't seem to get it right. I have tried the things we were taught at the course but I can't seem to get it right. Could you please take a look at it and lend a hand perhaps. Not even the console.log is printed out. Code in Clock.js: function clock () { let now = new Date() let h = now.getHours() let m = now.getMinutes() let s = now.getSeconds() m =

Firefox, query selector and the visible pseudo selector

无人久伴 提交于 2019-12-10 02:13:41
问题 Is there anyway to use a pseudo selector with Firefox's querySelector() or querySelectorAll() functions to detect visibility? In particular I want to be able to do something like this: elem.querySelector('#list .list-item:visible'); elem.querySelector('#section .sub-section:visible .title'); No need to worry about browser inconsistencies or other implementation, just Firefox. Thanks! EDIT: Visible is defined by display not being none and visibility not being hidden . 回答1: No, there isn't. The

Why is document null?

我是研究僧i 提交于 2019-12-08 13:48:42
问题 **UPDATED ** with a solution that comes close to working: I'm trying to get my 'skip to content' link to jump to the first focusable element after '#content-start'. login-base.component.ts: import { Component, OnInit } from '@angular/core'; import { Inject, Injectable } from '@angular/core'; import { DOCUMENT } from '@angular/platform-browser'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.scss'] }) export class BaseLoginComponent

How to set rounded buttons with background color and change color on pressed

这一生的挚爱 提交于 2019-12-06 13:43:18
问题 In my android app there is a rounded rectangle button with green colored background. i did this using .xml file <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:padding="10dp" android:shape="rectangle" > <solid android:color="#B5D397" /> <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> </shape> and android:background="@drawable/rounded_btn" in

Firefox, query selector and the visible pseudo selector

被刻印的时光 ゝ 提交于 2019-12-05 02:49:17
Is there anyway to use a pseudo selector with Firefox's querySelector() or querySelectorAll() functions to detect visibility? In particular I want to be able to do something like this: elem.querySelector('#list .list-item:visible'); elem.querySelector('#section .sub-section:visible .title'); No need to worry about browser inconsistencies or other implementation, just Firefox. Thanks! EDIT: Visible is defined by display not being none and visibility not being hidden . No, there isn't. The CSS specification doesn't define a :visible (or related) selector, and AFAIK Firefox doesn't implement non

Can I put logical operators in document.querySelectorAll? If so, how?

纵然是瞬间 提交于 2019-12-04 17:48:01
问题 Let's say I want to find all div elements and span inside p . Is it possible to get all what I want in a single `querySelectorAll" invocation? Conceptually it should be something like document.querySelectorAll("div | p span") (if | means or ). 回答1: Yes. You can use the same logical operators allowed in CSS: OR: chain selectors with commas document.querySelectorAll('div, p span'); // selects divs, and spans in ps AND: chain selectors without whitespace document.querySelectorAll('div.myClass');