This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
change text on button using jquery mobile.
I need to change a button text, I am using jQuery mobile.
Here is my html:
<fieldset>
<div><button type="submit" id="login_var">Login</button></div>
<div><button type="reset" >Reset</button></div>
</fieldset>
I have tried all of the examples on this page:
LINK and nothing is working for me.
Please help
I've had to do the same thing before, it's really not as obvious to do as it should be. Since jQM adds span tags inside your button, you need to change the value inside the span:
$("#login_var .ui-btn-text").text("NewText");
Similarly, if you wanted to change the icon, you could do:
$("#login_var .ui-icon").removeClass("ui-icon-arrow-l").addClass("ui-icon-arrow-r");
Edit:
Sorry I just noticed the link you posted in the question has the same solution, and you said that doesn't work for you. Maybe if you changed your buttons to
<a data-role="button"></a>
Instead of <button></button>?
Yeah you can use
$(function(){
$('#login_var').text('Ok').button('refresh');
});
As per http://jquerymobile.com/test/docs/buttons/buttons-methods.html, there are only three methods you can call on a button.
Related
This question already has answers here:
jQuery selector for id starts with specific text [duplicate]
(4 answers)
Closed 5 years ago.
can i change this button click
$('input[name="submit.one-click-premium-de.x"]').click().first();
to a button that has a wild card after first words?
$('input[name="submit.one-click*"]').click().first();
or something?
When the Button Name start with submit.one-click i will click this.
All things after "one-click" is okay. So i want like a wildcard there...
My click on top works but i want to have a start with one-click button...
I tried much strange things but thats not working
^= is the startsWith selector:
$('input[name^="submit.one-click"]').click().first();
https://api.jquery.com/attribute-starts-with-selector/
You can use ^= to do this. It works this way:
$('input[name^="submit.one-click"]').click().first();
This question already has answers here:
link to Print in a webpage
(2 answers)
Closed 8 years ago.
I am trying to add a print button for a form on the website that I maintain for a voluntary organization in Scotland. I would stress that I am not an expert in either HTML or Javascript but do my best.
The answer given by Murali to question 20101409 on 20th November 2013 looks as if it should work but does not. I suspect that I not named or defined something correctly.
My test webpage is: http://clanmacthomas.co.uk/Pages/TestCalculations.aspx
I strongly discourage the use <a href="javascript:..something.."> for any purpose, and especially the use of links to perform actions, preferring buttons instead.
If you have
<div>stuff</div>
<div>more stuff</div>
<input type="button" id="print" value="Print this page">
You can later attach a handler to it by using
<script>
document.getElementById("print").addEventListener("click", function() {
if (window.print) window.print();
});
</script>
If you are likely to want a print button on more than that one page, put that code in a .js file
/* printer.js */
document.getElementById("print").addEventListener("click", function() {
if (window.print) window.print();
});
There are nicer ways to do it if you are using jQuery, but you didn't mention that so I'm avoiding it.
You may want to read the SO question "Correct usage of addEventListener() / attachEvent()" since older versions of Internet Explorer use attachEvent instead of addEventListener.
To add a link that will open the print dialog on a webpage, include this link somewhere:
Print
This question already has answers here:
How to scroll an HTML page to a given anchor
(17 answers)
Closed 8 years ago.
I want browse directly to my site div by this way:
www.xyz.com/#divname
some sites I saw , I know there is a way to do it ,can anyone tell me the code
I have tried
window.location.href=#divname
but not scrolling.
Try
window.location.hash = '#divname';
Where #divname is the id of your div
Can you try this,
<body onload="window.location.hash = '#divname';">
That is called bookmark links, see here http://www.hyperlinkcode.com/bookmark.php.
To navigate to an anchor via javascript you can use this code:
window.location.hash = "#divname";
This topic is also a duplicate of the following:
How to scroll HTML page to given anchor using jQuery or Javascript?
Regards.
If you want to browse directly using a URL (as per your question), then there is absolutely no need for any javascript.
All you need to do is set an id for your div elements, that match the anchor tag you want to use. In the case of your example:
www.xyz.com/#divname
Then you would need an element like so:
<div id="divname">
</div>
Here is a working example
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)
I can't understand why this inner html script isn't working. I posted the javascript on jsFiddle. You can see it here: http://jsfiddle.net/JyV73/1/
I have two versions of the link. In the first the rewrite link is within a popup that needs to be closed and another opened with the proper text within the textarea.
In the second, there is just a link on the page that when it is clicked should hopefully open the popup with the proper text within wht textarea.
The only problem is that it doesn't work for the second version because of I must close the popup. If I comment out that first document.getElementById(id).style.display = 'none' then the plain link works, so my first thought is to create two function. But since this javascript is part of a php template file that is included I think it would be simpler on the php code to just solve this using pure javascript.
I'm still learning javascript, and any help would be appreciated. I hope I was clear. Thank you so much.
HTML
open
<div id="popup" class="popup"> Rewrite
</div>
<div id="new" class="popup">
<textarea id="new-text"></textarea>
</div>
<!-- This is the stuff that doesnt work for some reason Rewrite
<div id="new" class="popup">
<textarea id="new-text"></textarea>
</div>
-->
The Javascript
function rewrite(id, text) {
document.getElementById(id).style.display = 'none';
document.getElementById('new-text').innerHTML = text;
}
I am not entirely clear on what you are trying to do here, but from the way I read your code you want to set the value of the text area to a specific value.
here is how you do that: http://jsfiddle.net/JyV73/9/
function rewrite(id, text) {
$('#new-text').val(text);
}
You're not using pop-ups, you're using modals, which means its' a div inside the page that toggles visibility. You can access information from those components whether they are visible or not, fyi.
Still, Im not entirely sure on what you're trying to do here.
I changed document.getElementById('new-text').innerHTML = text; to document.getElementById('new-text').value = text; because it's the value attribute of the text box which you want to set.
Also each element on the page with an ID needs to have a unique ID (it seems like you might have been trying to reuse IDs at one point but maybe I'm wrong!)
I still haven't worked out exactly what you're trying to achieve but those changes needed to be made no matter what.
This code is sufficient to achieve your second goal though: http://jsfiddle.net/JyV73/19/
I added an onClick attribute (onClick="rewrite('popup', 'blah')") to your "open" link to do the writing to the textbox. :)