jquery question regarding text change
<script type="text/javascript">
$(function () {
var text3;
$('.HideButton').click(function () {
text3 = $('#MessageText').text;
var theButton = $(this);
$开发者_StackOverflow社区('#disclaimer').slideToggle('slow', function () {
theButton.val($(this).is(':visible') ? 'Hide' : 'Show');
});
$('<p>' + text3 + '</p>').addClass("new").insertAfter('#disclaimer');
return false;
});
});
updated...code above doesnt change the buttons text
<p id="disclaimer" > DDDDDDDDDDDDDDDDDDDDDDDDDD</p>
<asp:Button ID="Button1" CssClass="HideButton" runat="server" Text="Hide" />
I want the text of the button to change each time i press on it..But it doesnt
<p id="disclaimer" >
<input id="MessageText" type="text" />
</p>
<asp:Button ID="Button21" CssClass="HideButton" runat="server" Text="Hide" />
As message typed in the textbox..it should appear while "#disclaimer disappear
The will render out to a form element. This means you should use .val()
instead of .text()
Also as Neil has pointed out, you are returning before this gets executed.
$('.HideButton').click(function () {
$('#disclaimer').slideToggle('slow');
// return false;
if ($('#disclaimer').is(':visible')) {
$(this).val('Hide');
} else {
$(this).val('Show');
}
});
});
<p id="disclaimer" > DDDDDDDDDDDDDDDDDDDDDDDDDD</p>
<asp:Button ID="Button1" CssClass="HideButton" runat="server" Text="Hide" />
Thats because you returned before you canged any text.
remove the return ...;
(or move it to the end of the function)
Try returning false at the end ;)
Your original question was answered a few different times and a couple different ways. Now you've asked what is essentially a completely new question.
I recommend any further changes be formed into their own questions.
Is this what you now want?
http://jsfiddle.net/kasdega/99GaJ/1/
After return your code will never be executed. Try this
$('.HideButton').click(function () {
var theButton = $(this);
$('#disclaimer').slideToggle('slow', function(){
theButton.val($(this).is(':visible')?'Hide':'Show');
});
return false;
});
精彩评论