Skip to main content

Posts

Showing posts with the label jQuery

Static file content not served by IIS

Recently on encountering a issue where in the images / CSS / js and others being rendered with status as 200 (OK). But when looked in the browser, the content was not displayed. The static modules were enabled in windows features along with the MIME type mapping. Finally, when checking in the IIS Server, it was found that the Static module was missing in the handler registration. Updating that fixed the issue.

Dynamically adding HTML DOM elements Via jQuery

How to Add DOM Elements Via jQuery The following script and fiddle demonstrate how to add the DOM elements via the jQuery library ​ $(document).ready(function() { var el = $(" ").attr({ "type": "checkbox", "class": "select", "value": "hi" }); var lbl = $(" ").text("hi"); $(".op").append(el); $(".op").append(lbl); console.log(el); });​ To play around, the fiddle is here -- Saravanan

jQuery Tips

to select the first option in a select using jquery: $("#target option:first").attr('selected','selected'); to get the value of the first option tag in a select using jquery $("#target").val($("#target option:first").val()); to remove the "selected" from any options that might already be selected $('#target option[selected="selected"]').each( function() { $(this).removeAttr('selected'); } ); -- Saravanan

jQuery Fiddles

The following are js fiddles 1. For demo on how to append an option tag between another option tag dynamically using jquery link 2. A demo of sortables using jQuery UI [1.7.2] and jQuery [1.3.2] link 3. The following JS fiddle is used to check how the value of an emtpy text box is recevied at Javascript link

jQuery Tips

The following are useful tips for handling jQuery - Javascript library 1. To change the selected option based on the option tag's value , use the following code. $('#element option[value="no"]').attr("selected", "selected"); However, if multiple options can be selected, first deselect them using the following code HTML MarkUp Default Selection 1 Selection 2 -- Javascript with jQuery -- $("document").ready(function() { $("#b1").click(function() { $(".selDiv select.opts option").each(function() { $(this).removeAttr("selected"); }); var optSelValue = $("#txt").val(); $(".selDiv select.opts option[value=\"" + optSelValue + "\"]").attr("selected", "selected"); }); }); Full Sample