Combining Multiple attributes in jQuery


Below are some of the code snippets available in jQuery for you to combine your multiple lines of code:

Combining multiple css properties or element attributes:

Statement: Set the width and height attributes for a table with id=mytable
$(“#mytable”).attr({width:’50px’,height:’40px’});

Statement: Set the css properties of width, height, background-color for a div with id=mydiv
$(“#mydiv”).css({width:’50px’,height:’40px’,background-color:’#F2F2F2′});

Combining element multiple selector:

Statement: Set the width, height and background-color css properties for controls with id=mydiv1, mydiv2 and mydiv3

$(“#mydiv1, #mydiv2, #mydiv3”).css({width:’50px’,height:’40px’,background-color:’#F2F2F2′});

Combining attribute selectors:

Statement: Find out those elements with an id attribute, having ‘name’ ending with ‘mydiv’ and the ‘checked’ state being ‘checked’

$(“#mydiv[id][name$=’mydiv’][checked=’checked’]”).val();

Combining attribute selectors with psuedo properties:

Statement: Delete dropdown option values myvalue3, myvalue4 from a dropdown with id=mydiv

$(“#mydiv options:not([value=’myvalue1′][value=’myvalue2′]).remove();
$(“#mydiv options:[value=’myvalue3′],[value=’myvalue4′]”).remove();

Note: The coma separator in the last statement above will perform a repeat operation on the same element which implies that the above statement is a combined version of the below statements:

$(“#mydiv options:[value=’myvalue3′]”).remove();

$(“#mydiv options:[value=’myvalue4′]”).remove();
Setting multiple attributes for an element:

Statement: Create a new anchor tag and set its id, class and redirect url

$(‘</a>’, {
id : ‘myId’,
class : ‘myClass’,
href : ‘mytest.html’
});

Combining Objects in jQuery:

Statement: To combine or merge two objects in jQuery

var parentObject = { property1: false, property2: 5, property3: “foo” };
var options = { property1: true, property3: “bar” };

jQuery.extend(parentObject, options);
//Final values for parentObject { property1: true, property2: 5, property3: “bar” }

Happy Coding!!!

SharePoint Re-Deployment Bat File


A simple bat file that you can use for redeploying your WSPs:

Copy the following text in a notepad and Save As ‘Deployment.bat

stsadm -o retractsolution -name “ProjectA.Deployment.wsp” -immediate -url “http://localhost:2000/
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name “ProjectA.Deployment.wsp”
stsadm -o addsolution -filename “D:\ProjectA.Deployment.wsp”
stsadm -o deploysolution -name “ProjectA.Deployment.wsp” -immediate -allowgacdeployment -url “http://localhost:2000/” -force
stsadm -o execadmsvcjobs
iisreset
iexplore http://localhost:2000/
pause

Ensure that you modify the filename path in Line 4 to your respective paths and also the Site URL.

How to insert newline in you excel formulae


To add a newline or a hard return in front of certain text, we try the Find & Replace option, but ends up nowhere. Instead make use of the CHAR(10), MS has provided, in your formulaes.

Usage:

=CONCATENATE(“Heading1”,CHAR(10),”Content under Heading1″)

 

Let me take a complex example also, to get you the feel of the power of CHAR(10):

Before Text:

a. Open Firefox b. Enter the URL as http://www.google.com c. Click on enter

After Text:

a. Open Firefox

b. Enter the URL as http://www.google.com

c. Click on enter

Solution:

=CONCATENATE(IFERROR(MID(C4,SEARCH(“a. “,C4),SEARCH(“b. “,C4)-SEARCH(“a. “,C4)),””),CHAR(10),IFERROR(MID(C4,SEARCH(“b. “,C4),SEARCH(“c. “,C4)-SEARCH(“b. “,C4)),””),CHAR(10),IFERROR(MID(C4,SEARCH(“c. “,C4),LEN(C4)),””))

How to remove “Open” button from File Download Dialog options you get in your browser?


I received one client requirement sometime back asking for removing the “Open” button from the File Download popup you get when you are trying to download any file which cannot be viewed directly on the browser.

Inorder to remove the “Open” button, you can make use of one of the  “meta” tags HTML has given us.

<meta name=”DownloadOptions” content=”noopen”/>

Add this meta tag in your <head> tag and voila…. you can get rid of the”Open” button. See below:

 

Bat file to rename .js file to another format and back to .js


I faced a lot of issues with my mail exchange server quarantining my js files when i mail it my client. The way out of it was by renaming the .js file to .bak. But as the number of js files increased, it became a tedious process. So I thought of creating a bat file which could do two operations for me:

  1. Convert the .js files to .bak files
  2. Convert the .bak files to .js files

Here is the code you can use for these operations:

Convert .js to .bak (create_jstobak.bat):

@echo on
echo “This will convert all the .bak files to javascript(.js) files
rem Set CURRENTDIR=%CD%
rem ren “%CURRENTDIR%\javascript_files\*.bak” “*.js”
for /f “delims=” %%i in (‘dir /ad/s/b’) do ren “%%i\*.bak” “*.js”
 pause

Convert .bak to .js (create_baktojs.bat):

@echo on
echo “This will convert all the javascript(.js) files to .bak files
rem Set CURRENTDIR=%CD%
rem ren “%CURRENTDIR%\javascript_files\*.js” “*.bak”
for /f “delims=” %%i in (‘dir /ad/s/b’) do ren “%%i\*.js” “*.bak”
 pause

Remember:

  • Correct the path given in the snippet above
  • You can convert it to any other extension like .x or .y or .xyz instead of using bak
  • Save the above text in a notepad file as a “.bat” file.
  • Place the bat file in the appropriate location. Accordingly change the path mentioned in Line no. 4

Hope this helps!!

‘Add to Favourites’ button javascript


Here is a simple code, that i found useful from dynamicdrive. You can use for ‘Add to Favourites’ button in HTML. Add them in your head tag:

<script type=”text/javascript”>

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, “”)
}

</script>

You can then call this javascript in your button ‘onclick’ event like this:

javascript:bookmarksite(‘site_title’, ‘site_URL’)

Demo