$(document.activeElement) is not working in Firefox [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need to get the current active element on my web page I used
$(document.activeElement)[0].id
This is working fine in Internet Explorer, but in Firefox it always return empty string ""
Please tell me how can I get active element's id in Firefox?
Here is a simple scenario
I have 2 div with ID div1 and div2 respectively, now when user click on them I should get it's ID
Here is my markup
http://pastebin.com/BCW8ECMx

Why not use the event's target:
$(document).ready(function () {
$(document).click(function (e) {
alert(e.target.id);
});
});
JSFiddle example found here.

The problem is not in the code. But, the fact that, div cannot be active.
In fact, elements, which a user cannot interact, cannot be active.
For such elements, the id of the <body> will be returned.

Related

Select form element won't expand when clicked in fullcalendar [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
In the following fullcalendar example (using v5.3.2) I've added a select element to the events, but the select elements won't expand when clicked, and so the value can't be changed.
I've updated the code example to insert the select tag into the DOM via the eventDidMount callback (which is what I do in my own code) and added jquery to add the event handler for the clicks on the select. You can see the clicks triggering in the console, but the select won't actually expand.
Is there any way to allow the select elements to be functional?
eventDidMount: function(arg) {
let content = $('<select><option>1</option><option>2</option></select>')
$(content).on('click', function(evt){
console.log(evt.target.tagName)
})
$('.fc-event-time', arg.el).before(content)
}

on click function not getting called [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to not display element after it was clicked, but the onclick method gets called when the page loads and then it does not get called when I click it. This is my code.
$(document).ready(function() {
$(".close").on('click', function(){
$(this).parent().parent().css("display","none");
});
}
What's the problem here?
The question is unclear. But your element is either not available on the dom from the beginning or you have not selected properly the element you want to hide.
Try this:
$(document).ready(function() {
$("body").on('click', '.close',function(){
$(this).closest("insert-element-name").css("display","none");
});
}

HTML: Navigate to a different url using button [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need to create a link or a button so that users can navigate to different urls (needs to be generated in a js function based on values selected in multiple dropdown)
I tried with a button but it doesn't navigate to the link, and with not able to change values of href it adds to previous values.
Can you please help
function link(url){
window.location.assign(url);
}
<button onclick="link('http://www.stackoverflow.com/')">Go to Stack Overflow without using an <a>!</button>
Try this:
https://jsfiddle.net/ykc8mLwj/
$(function() {
$("#id-of-your-select").on("change", function() {
$("#id-of-your-link").attr("href", $(this).val());
});
}

How to handle the key press event in javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I try to handle the key press event in javascript, after user press a key on keyboard, it will print the pressed key on screen. I know I need to handle the onkeydown event, but how to do that in detail?
You can use jQuery to do this job, using jQuery will make your program run well in different browsers.
$(function(){
$(document).keypress(function(event){
console.log(event.which);
});
})
Above code uses keypress function to handle key press event, and print the pressed key's key code to your browser console

Type in Secret Message get Forwarded [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get forwarded to a page called 'test.html' by typing in the sentence 'hello' on the page. For example, when I type in 'hello' on the page, I would get forwarded to test.html . It wouldn't be in a text box; I would type it without seeing what I'm typing. I've researched this online but can't find anything on this topic.
I don't know what purpose it will serve but You can do something like that.
Add keypress listener on document.
Maintain one variable for holding the typed text say sec.
in your key press listener,
Concatenate the pressed key with the sec and compare if
sec=="hello" do redirect
DEMO
Javascript
(function(){
document.addEventListener("keypress",fun);
var sec='';
function fun(e){
sec += String.fromCharCode(e.keyCode);
if(sec=="hello"){
alert("Hello typed!"); //replace this with redirect
sec='';
}
}
})();

Categories

Resources