.focus() event is not working [duplicate] - javascript

This question already has answers here:
focus() not working in safari or chrome
(6 answers)
Closed 3 years ago.
when my php page loads some jQuery should set focus to my input textbox but it does not
I have tried css selectors like input[tabindex=1] and #31 but to no avail...
here is the jQuery (version 1.7.1)
$(function() {
$('input[tabindex=1]').focus(); // also tried $('#31').focus();
});
and here is the HTML
<input tabindex='1' type='text' class='tablefilter' id='31' style='width:80px;border:inset 2px grey;background-color:white;font-size:12px;border-radius:0px;-moz-border-radius:0px;-webkit-border-radius:0px;'/>
any clues as to why this isn't working?

check this out, i just tried your code, it works. which version of jquery are you using? which browser are you using, try open console to see, if there is an exception.
here is the demo: DEMO

Related

how to run a function after html value change [duplicate]

This question already has answers here:
jQuery Event : Detect changes to the html/text of a div
(13 answers)
Closed 5 years ago.
I am doing a simple hover scrollbar project. I want to change the height of thumb when someone change the contents in html tag by prepend(),append(),html()..etc. how can I do this? I googled it and found answers like
$('.class').html('value').trigger(somefunction())
But it is not the answer. Because I am not the developer of other js codes. I want to do this with only my script file.
here is my project :-
https://github.com/rameshkithsiri/hoverscroll
Here is way of doing so , you can use DOMSubtreeModified events. But look out It before using it.
$("body").on('DOMSubtreeModified', ".myCLASS", function() {
alert($(this).html());
});
setTimeout(function(){ $(".myCLASS").html("my Test") }, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="myCLASS"></div>

JQuery click is not working [duplicate]

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 6 years ago.
I have following simple html block:
<span class="change_ordering show-list" data-ordering-by="product_list" data-ordering-direction="desc">By list</span>
Then, I have following js-code:
$(document).ready(function() {
$('.show-list').click(function() {
console.log('qwe');
});
});
When I click on it - nothing happens. But when I paste this js-code to Google Chrome JS console, it works perfectly. JS works fine on my site, I can make other JQuery actions. I also tried to write $('.change_ordering.show-list') and $('span.change_ordering.show-list') and $('span.show-list'), but still no progress. What I'm missing?
EDIT: This element is not drowing by ajax. I don't understand why it's duplicate.
Please apply click using following way
$(document).on("click",".show-list",function(){})
It will work

jQuery won't clear form [duplicate]

This question already has answers here:
How to reset a form using jQuery with .reset() method
(16 answers)
Closed 8 years ago.
I KNOW this question has been asked numerous times as I have used this website's solutions to no avail. I currently have this implementation:
$("input:reset").click(function () {
$('#answer_2').html('License number is not long enough');
$('#answer_1').html('');
$('#data_entry').each (function(){
this.reset();
});
});
I know the selector is correct as the two html changes (I put them in to confirm I was selector for the reset button click correctly) occur as they should.
Here is my form declaration:
<form name="data_entry" id="data_entry" method="post" action="">
The problem is I keep getting the error that there is no 'reset' function and the form is never cleared. This is my most recent attempt at following answers to this problem on stackoverflow site. Please help.
Why reset when you want to clear/empty?
this.empty();
might do the trick?
Your each is wrong and it's unnecessary.
$('#data_entry').get(0).reset();
This should work because you got the right element but $() returns a jQuery object, not a DOM element. get will grab your DOM element and then you can use reset() (which is not a jQuery function)

Only one jQuery event runs per refresh [duplicate]

This question already has answers here:
Find currently visible div in jquery
(5 answers)
Closed 3 years ago.
Only one jQuery event runs per refresh of the page. What am I doing that's so wrong?
$("#contact_link_email").on("click",function(){
$("#contact-form").replaceWith('<h2>Email heading</h2>');
});
$("#contact_link_facebook").on("click",function(){
$("#contact-form").replaceWith('<h2>Facebook heading</h2>');
});
$("#contact_link_twitter").click(function(){
$("#contact-form").replaceWith('<h2>Twitter heading</h2>');
});
$("#contact_link_gplus").click(function(){
$("#contact-form").replaceWith('<h2>GPlus heading</h2>');
});
Once one of those events runs, $("#contact-form") doesn't reference anything. If you want to replace it with something, try making that something have the same id.

innerText alternative in Firefox [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
InnerText alternative in mozilla
I have this code
<div id="code">My program<br />It is here!</div>
<script type="text/javascript">
var program=document.getElementById('code');
ShowLMCButton(program.innerText);
</script>
It works in IE but in firefox, innerText does not work. How can I use this in firefox? I have tried .text() but it doesn't want to work! I need the text to be in the form "My program\n It is here!" It can't be textContent because that copies the html tags.
What this is, is to copy a VB script from a site and paste it straight into a program and it must include all the new lines, white space etc.
ShowLMCButton() is a script that is "Click to Copy" - http://www.lettersmarket.com/view_blog/a-3-copy_to_clipboard_lmcbutton.html
use textContent for firefox
ShowLMCButton(program.innerText || program.textContent)
You can use JQuery to do this:
Live Demo
ShowLMCButton($('#code').text());

Categories

Resources