I'm trying to get the following jquery toggle to work on IE, FF, and as many browsers as possible, but currently it works only on FF. Here, I've got the toggle available (between drop-down select and textarea) only when a certain option is selected ("bbb" in this case). Also, is there a better way to write the same script (a cleaner way, may be)?. Click here to check out what I've got right now.
Many thanks in advance.
$(document).ready(function() {
$("#link a").hide();
if ($("#sel").val() == 'bbb') $("#link a").show();
$("#sel_id").change(function() {
if ($("#sel").val() == 'bbb') {
$("#link a").show();
} else {
$("#link a").hide();
$("#link").show();
}
});
$('#txtbox').hide();
$('#link a').click(function() {
$('#txtbox').slideToggle();
$(this).text($(this).text() == "(Another input option)" ? "(Method 1)" : "(Another input option)");
$('#sel_id').show();
if ($('#link a').text() == '(Method 1)') {
$(this).prev('div').hide();
$('#link').prev().remove('div');
$('#link').before("<div>This is another input option</div>");
$('#sel_id').hide();
$('#cp').val('');
$('#sel').val('');
} else {
$('#link').prev().remove('div');
$('#link').before("<div>Method 1</div>");
}
$("#len").val('None');
return false;
});
});
<div id="link">
<div>Method 1</div><a href="#">(Another input option)</a>
</div>
<div id="sel_id">
<select id="sel" name="sel">
<option value="None" selected></option>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
</select>
</div>
<div id="txtbox">
<div style="margin-top: 5px;" class="tab">copy and paste:<br />
<textarea rows="5" cols="64" id="cp" name="cp"></textarea>
</div>
</div>