Javascript

Dynamically Changing src Attribute of script

I had a situation where I wanted to change the src of a script dynamically before the script runs.
Given the following code, we needed to change src before the script gets executed:

<html>
    <body>
        <script language="JavaScript" type="text/javascript" src="..."></script>
    </body>
</html>

So simply (This simply took a couple of hours!) I did this:

<script language="JavaScript" type="text/javascript">
    url = ....
    function staticLoadScript() {
            document.write('<script language="JavaScript" type="text/javascript" src="', url, '"><\/script>');
           }
        staticLoadScript();
</script>

JQuery Selectors

$("a").click(function() {
     alert("Hello world!");
   });

In the above code $("a") is a jQuery selector. It selects all 'a' elements. $ itself is an alias for the jQuery "class", therefore $() constructs a new jQuery object. The click() function is a method of the jQuery object. It binds a click event to all selected elements and executes the provided function when the event occurs.
Selecting item can be done down a path, like: $("div > ul a")

If you want to select just one element use #itsID inside single or double quotes:

//With id:  
    $('#theId') 
//With class:  
    $('.theCssClass')

<input type="button" id ="x" value="Test" />
<input type="button" value="Disable" onclick="$('#x').attr('disabled','disabled')"/>

setInterval

setTimeout() triggers expression only once but setInterval() keeps triggering expression again and again (unless you tell it to stop).

window.setInterval("function()",300);
window.setInterval(function showAnn(){/*do something*/ },3000);

DWR and Spring Integration

comming soon

page_revision: 11, last_edited: 1250120143|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License