All In One Script
MENU

closing tag in HTML

by 5:33:00 AM
undefined
closing tag in HTML I'm trying jquery now. When I included the jquery.js as follows <script type="text/javascript" src="jquery.js" /> the code doesn't worked properly. Actually it is just a simple hello world program. I just called a jQuery specific function. But that was not working if I include the file as above. But when I changed the closing like this <script type="text/javascript" src="jquery.js"></script> the code worked well. What is the difference? Answer: <script /> is valid XML, but invalid HTML. If you serve your

Why don't self-closing script tags work?

by 5:17:00 AM
undefined
Why don't self-closing script tags work? What is the reason browsers do not correctly recognize: <script src="foobar.js" /> <!-- self-closing script tag --> Only this is recognized: <script src="foobar.js"></script> Does this break the concept of XHTML support? Note: This statement is correct at least for all IE (6-8 beta 2). Solution: XHTML 1 specification says: С.3. Element Minimization and Empty Element Content        Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph)

jQuery document.createElement equivalent?

by 5:12:00 AM
undefined
jQuery document.createElement equivalent? I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going on. var d = document; var odv = d.createElement("div"); odv.style.display = "none"; this.OuterDiv = odv; var t = d.createElement("table"); t.cellSpacing = 0; t.className = "text"; odv.appendChild(t); I would like to know if there is a better way to do this using jQuery. I've been experimenting with: var odv = $.create("div"); $.append(odv); // And many more But I'm not sure if this is any better. Answer: here's your example

What is the best way to add options to a select from an array with jQuery?

by 5:44:00 AM
undefined
What is the best way to add options to a select from an array with jQuery? What is the best method for adding options to a select from a JSON object using jQuery? I'm looking for something that I don't need a plugin to do, but would also be interested in the plugins that are out there. This is what I did: selectValues = { "1": "test 1", "2": "test 2" }; for (key in selectValues) { if (typeof (selectValues[key] == 'string') {

What is the best way to detect a mobile device in jQuery?

by 5:42:00 AM
undefined
What is the best way to detect a mobile device in jQuery? Is there a solid way to detect whether or not a user is using a mobile device in jQuery? Something similar to the CSS @media attribute? I would like to run a different script if the browser is on a handheld device. The jQuery $.browser function is not what I am looking for. Solution: Instead of using jquery you can use simple javascript to detect it: if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { // some code.. }

How to determine if variable is 'undefined' or 'null'?

by 5:40:00 AM
undefined
How to determine if variable is 'undefined' or 'null'? How do I determine if variable is undefined or null? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ //DO SOMETHING }; <div id="esd-names"> <div id="name"></div> </div> But if I do this, the JavaScript interpreter halts execution. Answer: You can do this: if (variable == null){ // your code here. } Check MDN for details on equality tests in JS. null == undefined is true, but null === undefinedis false. Thus the code above, as is, will catch

Creating a div element in jQuery

by 5:39:00 AM
undefined
Creating a div element in jQuery How do I create a div element in jQuery? solution: First select the parent element with something like $("#id"), $("element") or $(".class") Then use the .append("<div>foo</div>") function. Alternatively, you can use the .html() as mentioned in a different answer. $("#foo").append("<div>hello world</div>") http://stackoverflow.com/questions/867916/creating-a-div-element-in-jquery

Event binding on dynamically created elements?

by 5:37:00 AM
undefined
Event binding on dynamically created elements? I have a bit of code where I am looping through all the select boxes on a page and binding a .hoverevent to them to do a bit of twiddling with their width on mouse on/off. This happens on page ready and works just fine. The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound. I have found this plugin (jQuery Live Query Plugin), but

Instagram