HTML-encoding lost when attribute read from input field

EDIT: This answer was posted a long ago, and the htmlDecode function introduced a XSS vulnerability. It has been modified changing the temporary element from a div to a textarea reducing the XSS chance. But nowadays, I would encourage you to use the DOMParser API as suggested in other anwswer. I use these functions: function … Read more

Using jQuery to center a DIV on the screen

I like adding functions to jQuery so this function would help: jQuery.fn.center = function () { this.css(“position”,”absolute”); this.css(“top”, Math.max(0, (($(window).height() – $(this).outerHeight()) / 2) + $(window).scrollTop()) + “px”); this.css(“left”, Math.max(0, (($(window).width() – $(this).outerWidth()) / 2) + $(window).scrollLeft()) + “px”); return this; } Now we can just write: $(element).center(); Demo: Fiddle (with added parameter)

Uncaught ReferenceError: $ is not defined?

You should put the references to the jquery scripts first. <script language=”JavaScript” type=”text/javascript” src=”https://stackoverflow.com/js/jquery-1.2.6.min.js”></script> <script language=”JavaScript” type=”text/javascript” src=”/js/jquery-ui-personalized-1.5.2.packed.js”></script> <script language=”JavaScript” type=”text/javascript” src=”/js/sprinkle.js”></script>

Is there a link to the “latest” jQuery library on Google APIs? [duplicate]

Up until jQuery 1.11.1, you could use the following URLs to get the latest version of jQuery: https://code.jquery.com/jquery-latest.min.js – jQuery hosted (minified) https://code.jquery.com/jquery-latest.js – jQuery hosted (uncompressed) https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js – Google hosted (minified) https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js – Google hosted (uncompressed) For example: <script src=”https://code.jquery.com/jquery-latest.min.js”></script> However, since jQuery 1.11.1, both jQuery and Google stopped updating these URL’s; they will … Read more

How do you select a particular option in a SELECT element in jQuery?

A selector to get the middle option-element by value is $(‘.selDiv option[value=”SEL1″]’) For an index: $(‘.selDiv option:eq(1)’) For a known text: $(‘.selDiv option:contains(“Selection 1”)’) EDIT: As commented above the OP might have been after changing the selected item of the dropdown. In version 1.6 and higher the prop() method is recommended: $(‘.selDiv option:eq(1)’).prop(‘selected’, true) In … Read more

How to remove close button on the jQuery UI dialog?

I have found this worked in the end (note the third line overriding the open function which find the button and hides it): $(“#div2”).dialog({ closeOnEscape: false, open: function(event, ui) { $(“.ui-dialog-titlebar-close”, ui.dialog || ui).hide(); } }); To hide the close button on all dialogs you can use the following CSS too: .ui-dialog-titlebar-close { visibility: hidden; … Read more

How to break out of jQuery each loop?

To break a $.each or $(selector).each loop, you have to return false in the loop callback. Returning true skips to the next iteration, equivalent to a continue in a normal loop. $.each(array, function(key, value) { if(value === “foo”) { return false; // breaks } }); // or $(selector).each(function() { if (condition) { return false; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)