Below code is working fine in Firefox & Chrome, but it is not working in IE.
Can someone please let me know the alternate to hiding select Dropdown options?
I tried with CSS style display: none as well but not no luck.
$j("#id option[value='test']").hide();
I spent lot of time to search on google related to same issue but changed my approach i tried the below scenario its worked like a charm for me
$j("#shipping_method optgroup[label='Free Shipping']").clone("optgroup[label='Free Shipping']").insertAfter("#shipping_method_form");
$j("#shipping_method optgroup[label='Free Shipping']").remove();
$j(".box-content .fedex").appendTo("#shipping_method");
#shipping_method_form is my select box id
above is an example from my scenario please take a look
hope this will be better solution for all browsers
$j("#id option[value='test']").hide();
// use proper Id correct.
Replace #id with proper id of the element.
$("option[value='test']").hide(); // here I assuming that you are not using ID
$("#idName option[value='test']").hide(); // here I assuming that you are using ID and replace `idName` with your IDs.
Related
I am using a Jquery plugin called datetimepicker and works great in Firefox but not in IE8. I narrowed down the issue to be with the jquery selector. I have a table with a class named sm_whiteboard and in that table there's an input box with the ID Next_x0020_update_x0020_at (this ID dynamically changes which is what I did ID*).
$("table.sm_whiteboard [id*=Next_x0020_update_x0020_at]").datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
This code works great in firefox but not in IE8. It doesn't give me any errors in the console in IE8. If I select only the input like this $("[id*=Next_x0020_update_x0020_at]") it works in IE8.
Any ideas where I could be going wrong?
Thanks to A. Wolff I figured out that the problem was due to a simple character issue in my class name. Seems like IE8 is case sensitive so had to make sure the class name was matching exactly with all the capital letters as well.
Thanks everyone!
$("table.SM_whiteboard [id*=Next_x0020_update_x0020_at]").datetimepicker({
addSliderAccess: true,
sliderAccessArgs: { touchonly: false }
});
I use the following code to reset the selected index of a select list in IE:
$("#list")[0].selectedIndex = -1
However, that doesnt appear to work in FF and Chrome. Can anyone tell me what the correct way to achieve this would be?
Use the .prop method of jQuery. Documentation can be found here.
Get:
$("#list").prop("selectedIndex");
Set:
$("#list").prop("selectedIndex",-1);
Why not this?
$("#list option").attr("selected", false);
This is related to Adding options to a <select> using jQuery? but has a different focus
My problem is that I am not able to append option-elements to a select in IE8.
When changing the engine to IE7 in IE's developer-tools it does work.
It also works in FF and Chrome.
var valT = "some Text";
var charsToIgnore = 2;
var o = new Option(valT.slice(charsToIgnore), valT);
$(o).html(valT.slice(charsToIgnore));
$('#availablePages').append(o);
another method I tried:
$('<option/>', {value: valT, text: valT}).appendTo("#availablePages");
availablePages is the id of my select. The select does not contain any elements when the page is received by the client. My doctype is <!DOCTYPE html>.
I also tried to remove all other scripts and css from my site to make sure no side-effects apply.
Edit:\ Thanks for downvoting! It's not my fault if provided solutions do not work in all IE8-versions. Since my question was What DOES work in all IE8-versions? it is, from my point of view, understandable that I do not accept answers which do not work for me. As you can see in Adding options to a <select> using jQuery? I am not the only one for whom the other replies here do not work.
Using the Up-/Down-Vote functionalities as channel for your own mood is no good Wiki/QA-behaviour.
This should just do the trick for you:
$('#availablePages').append(new Option(valT.slice(charsToIgnore), valT));
(Tested and working in IE8)
What worked for me
var o = new Option("option text", "value");
$(o).html("option text"); // Without this line it does not work..
$("#availablePages").append(o);
What I also had to change / what one should consider:
display: table; is NOT allowed to be applied. For some reason it breaks everything.
I've got the following jQuery code for getting the first character of the string value of the selected option of an html select box.
var mode = $("#mode :selected").text()[0];
"mode" is the id of the html select element I want. This is not working in IE at the moment - does anyone know why that might be?
EDIT: Sorry everyone, it was nothing to do with jQuery. IE just wanted
var mode = $("#mode :selected").text().charAt(0);
I'm not sure why I thought the [0] would work in the first place. Thanks anyway.
maybe the problem is with not specifying the 'option'
we use this code in several of our projects and this does work in IE
$("#ComboBox option:selected").text()
I have a <select> list, which has been populated with several options, but want to remove those options to start again.
I am using jQuery and have tried the following:
$("#selectId").length = 0;
But this seems to have no effect.
Part of my problem is that I am using Firebug to debug the JavaScript, but the debugger does not break at the breakpoint, so I cannot see what is going on. Should it break when the JavaScript is within the <head> of my HTML file?
this would do:
$('#selectId').html('');
This works too.
$("#selectId option").remove();
$("#selectId").empty(); works for me.
The $("#selectId option").remove(); removed the select from the DOM.
Currently using jQuery JavaScript Library v1.7.1
The fastest way to accomplish this:
$("#selectId").empty();
Here are some tests:
http://jsperf.com/find-remove-vs-empty
I take no credit for these tests.
See this stack overflow question: How do you remove all the options of a select box and then add one option and select it with jQuery?
$("#selectId").options.length = 0;
That won't actually work as written because it's using a jQuery selector. It'd work if you used a straight DOM getElementById on the select list, though. Either AKX's or d.'s responses will set you right.
If without jquery:
javascript SELECT remove()
Try This for Multiple Select Drop Down.
$('#FeatureId').multiselect("deselectAll", false).multiselect("refresh");