Dushyant Patel’s Blog

Remove HREF attribute using Regular Expression & jQuery

Requirement is to get the content of the specific DIV remove HREF attributes from all and assign new content (without HREF attributes) to printer friendly page.

For Demo : onClick of button storing content of <DIV class=”content1″>. Using Regular Expression removing HREF and then assign that content to <DIV class=”content2″>.

HTML Code:

<div class="content1">
<a href="javascript:testfunction(4933)">This is test link 1</a>
<p>This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. </p> <a href="test2.html">This is test link 2</a> <p>This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. </p> <a href="test2.html">This is test link 3</a> <p>This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. </p> <a href="test3.html">This is test link 4</a> <p>This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. This is dummy text, Please don't read. </p> </div> <div> <input name="testbtn" id="testbtn" type="button" value="Remove" /> </div> <div class="content2"></div>

CSS Code:

<style type="text/css">
body {
   font-family:Verdana, Arial, Helvetica, sans-serif;
   font-size:11px;
 }
.content1, .content2 {
   width:400px;
   margin:10px;
   background-color:#efefef;
   border:1px solid #ccc;
   float:left;
   padding:10px;
}
.content2 {
   float:right
}
.btndiv {
   width:100px;
   float:left;
}
</style>

jQuery Code:

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {

  $("input#testbtn").click(function () {
     var printcontent = $("div.content1").html();
     printcontent = printcontent.replace(/\s*href\s*=\s*('[^']*'|"[^"]*")/ig,'');
     $("div.content2").html(printcontent);
  });
});

</script>

Filed under: Technology

Position DIV to element using jQuery

Requirement is how to position DIV to some element on the fly using jQuery?

Using jQuery position(), can access position of element and assign position to DIV on the fly.

For Example: onClick of link element access the position of <a> element and on the base of that assign position to DIV.

HTML Code:

<div>
   <a href="#" id="pospayerlnk">Position Layer</a>
   <div id="testDiv">
         Test
   </div>
</div>

CSS Code:

body {
   font-family:Verdana, Arial, Helvetica, sans-serif;
   font-size:11px;
}

.center-main {
   width:400px;
   margin:auto;
   margin-top:100px;
}

#testDiv {
   width:100px;
   height:100px;
   position:absolute;
   top:10px;
   left:10px;
   background-color:#CCCCCC;
   border:1px solid #666666;
}

a#pospayerlnk {
   border:1px solid #3366CC;
   height:18px;
   display:block;
   width:100px;
   color:#0066CC;
   line-height:18px;
   text-decoration:none;
   text-align:center;
}
</style>

jQuery Code:

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function () { $("a#pospayerlnk").click(function () { var position = $(this).position(); $("div#testDiv").css("left", position.left); $("div#testDiv").css("top", position.top+20); }); }); </script>

Filed under: Technology

Typetester – online application for comparison of the fonts for the screen

The Typetester is an online application for comparison of the fonts for the screen. Its primary role is to make web designer’s life easier. As the new fonts are bundled into operating systems, the list of the common fonts will be updated.

Read More…

Filed under: Technology

CSS issue Input width=100% & padding in IE issue

I was having a problem with width on input[text] fields in IE

In IE, it renders the width as 100% + 10px(padding which i have given for search icon).

HTML:

<div class=”container”>
<input type=”text” value=”Enter Keyword” name=”searchbox”/>
</div>

<div class=”button_div”>
<input type=”submit” name=”button” id=”button” value=”Search” />
</div>

CSS:

.container{ width:250px; float:left}
.button_div {width:100px; float:right}
.container input{ width:100%; max-width:100%; padding-left:10px;}

Soltuion:
Wrap the input field with a 100% div with no padding and no margin and set the input field inside that div to 100% width with a padding of 10px

<div class=”container”>
<div style=”width:100%”>
<input type=”text” value=”Enter Keyword” name=”searchbox”/>
</div>
</div>

Filed under: Technology

Beyond Compare is the ideal tool for comparing files and folders

I would like to share one good software with you all, for comparing files and folders.

Beyond Compare provides users with extensive side-by-side file comparison and management. Synchronize files between laptop and PC, home and office, etc. Compare directory trees side-by-side with mismatches highlighted. Display text files side-by-side with changes highlighted. Great for merging changes to source code.

Website Link : http://www.scootersoftware.com/index.php

Filed under: Technology, ,

How to access element of parent window from an iframe with jQuery

I got one requirment that need to assign value of check box which are in iframe to input box of parent window using jQuery.

I found solution which i want to share with you.

Parent Window Code:

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script src=”js/jquery-1.3.2.js” type=”text/javascript”></script>
</head>
<body>
<form id=”form1″ name=”form1″ method=”post” action=””>
<div id=”inputbox”>
<input name=”” type=”text” id=”selectedchkbox” width=”400″ size=”50″/>
</div>
<br />
<div id=”iframe”>
<iframe src=”iframeCheckbox.html” width=”400″ height=”400″></iframe>
</div>
</form>
</body>
</html>

iframe code:

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script src=”js/jquery-1.3.2.js” type=”text/javascript”></script>
<script type=”text/javascript”>

$(document).ready(function() {
$(“a.submitlist”).click(function() {
var newtxt = ”;
var chkbx = $(“div#checkboxlist input”)
for(var i = 0; i < chkbx.length; i ++) {
if(chkbx[i].type == ‘checkbox’ && chkbx[i].checked === true) {
if(newtxt.length !== 0) {
newtxt += ‘,’;
}
newtxt += chkbx[i].value;
}
}
parent.top.$(“input#selectedchkbox”).val(newtxt);
});
});

</script>
</head>
<body>
<form id=”form1″ name=”form1″ method=”post” action=””>
<div id=”checkboxlist”>
<p>
<input type=”checkbox” name=”checkbox1″ id=”checkbox1″ value=”checkbox1″ />
checkbox 1<br />
<input type=”checkbox” name=”checkbox2″ id=”checkbox2″ value=”checkbox2″ />
checkbox 2<br />
<input type=”checkbox” name=”checkbox3″ id=”checkbox3″ value=”checkbox3″ />
checkbox 3<br />
<input type=”checkbox” name=”checkbox4″ id=”checkbox4″ value=”checkbox4″ />
checkbox 4<br />
<input type=”checkbox” name=”checkbox5″ id=”checkbox5″ value=”checkbox5″ />
checkbox 5</p>
<p>
<label><a href=”#”>Submit</a></label>
<br />
</p>
</div>
</form>
</body>
</html>

Using “parent.top “, can target parent window and then use $(”input#selectedchkbox”).val(newtxt); to select targeted element and assign value.

Filed under: Technology

Gujarati boy rules world’s senses

I am following Narendra Modi on Twitter, and i found this story from his personal site.

This is about Pranav Mistry, a 28-year-old MIT researcher, who has got intangible digital information into the tangible world, allowing us to interact with this information via natural hand gestures.That’s wear ur world (WUW) — a wearable gestural interface. So, when you pick up your airline ticket and find that it is telling you that your flight is delayed, thank this boy from Palanpur, the land of diamantaires that has now produced a gem of a techie.

Read More…

Filed under: Technology

Awesome Conversation! About God

Few days back I received an email from one of my friend. It was all about conversation between professor and student about God. Awesome !!!. I though let me share with you.

— Start —

An atheist professor of philosophy speaks to his class on the problem science has with God, The Almighty.

He asks one of his new students to stand and…..

Prof: So you believe in God?

Student: Absolutely, sir.

Prof: Is God good?

Student: Sure.

Prof: Is God all-powerful?

Student: Yes.

Prof: My brother died of cancer even though he prayed to God to heal him. Most of us would attempt to help others who are ill. But God didn’t. How is this God good then? Hmm?

(Student is silent.)

Prof: You can’t answer, can you? Let’s start again, young fella. Is God good?

Student: Yes.

Prof: Is Satan good?

Student: No.

Prof: Where does Satan come from?

Student: From…God….

Prof: That’s right. Tell me son, is there evil in this world?

Student:Yes.

Prof: Evil is everywhere, isn’t it? And God did make everything. Correct?

Student: Yes.

Prof: So who created evil?

(Student does not answer.)

Prof: Is there sickness? Immorality? Hatred? Ugliness? All these terrible things exist in the world, don’t they?

Student: Yes, sir.

Prof: So, who created them?

(Student has no answer.)

Prof: Science says you have 5 senses you use to identify and observe the world around you. Tell me, son…Have you ever seen God?

Student: No, sir.

Prof: Tell us if you have ever heard your God?

Student: No, sir.

Prof: Have you ever felt your God, tasted your God, smelt your God? Have you ever had any sensory perception of God for that matter?

Student: No, sir. I’m afraid I haven’t.

Prof: Yet you still believe in Him?

Student: Yes.

Prof: According to empirical, testable, demonstrable protocol, science says your GOD doesn’t exist. What do you say to that, son?

Student: Nothing. I only have my faith.

Prof: Yes. Faith. And that is the problem science has.

Student: Professor, is there such a thing as heat?

Prof: Yes.

Student: And is there such a thing as cold?

Prof: Yes.

Student: No sir. There isn’t.

(The lecture theatre becomes very quiet with this turn of events.)

Student: Sir, you can have lots of heat, even more heat, superheat, mega heat, white heat, a little heat or no heat. But we don’t have anything called cold. We can hit 458 degrees below zero which is no heat, but we can’t go any further after that. There is no such thing as cold . Cold is only a word we use to describe the absence of heat . We cannot measure cold. Heat is energy . Cold is not the opposite of heat, sir, just the absence of it.

(There is pin-drop silence in the lecture theatre.)

Student: What about darkness, Professor? Is there such a thing as darkness?

Prof: Yes. What is night if there isn’t darkness?

Student : You’re wrong again, sir. Darkness is the absence of something. You can have low light, normal light, bright light, flashing light….But if you have no light constantly, you have nothing and it’s called darkness, isn’t it? In reality, darkness isn’t. If it were you would be able to make darkness darker, wouldn’t you?

Prof: So what is the point you are making, young man?

Student: Sir, my point is your philosophical premise is flawed.

Prof: Flawed? Can you explain how?

Student: Sir, you are working on the premise of duality. You argue there is life and then there is death, a good God and a bad God. You are viewing the concept of God as something finite, something we can measure. Sir, science can’t even explain a thought. It uses electricity and magnetism, but has never seen, much less fully understood either one.To view death as the opposite of life is to be ignorant of the fact that death cannot exist as a substantive thing.

Death is not the opposite of life: just the absence of it.
Now tell me, Professor.Do you teach your students that they evolved from a monkey?

Prof: If you are referring to the natural evolutionary process, yes, of course, I do.

Student: Have you ever observed evolution with your own eyes, sir?

(The Professor shakes his head with a smile, beginning to realize where the argument is going.)

Student: Since no one has ever observed the process of evolution at work and cannot even prove that this process is an on-going endeavor, are you not teaching your opinion, sir? Are you not a scientist but a preacher? (The class is in uproar.)

Student: Is there anyone in the class who has ever seen the Professor’s brain?

(The class breaks out into laughter.)

Student: Is there anyone here who has ever heard the Professor’s brain, felt it, touched or smelt it? No one appears to have done so. So, according to the established rules of empirical, stable, demonstrable protocol, science says that you have no brain,sir. With all due respect, sir, how do we then trust your lectures, sir?

(The room is silent. The professor stares at the student, his face unfathomable.)

Prof: I guess you’ll have to take them on faith, son.

Student: That is it sir…. The link between man & god is FAITH . That is all that keeps things moving & alive.

NB: I believe you have enjoyed the conversation…and if so…you’ll probably want your friends/colleagues to enjoy the same…won’t you?….

this is a true story, and the

student was none other than……….

APJ Abdul Kalam , the former president of India

Filed under: Personal

What is jQuery??? Where to learn jquery???

I have a friend who has been asking me What is jQuery? & Where to learn jquery?

www.jquery.com has itself all information available.

“jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.”

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

You can start learning it from its Tutorial(http://docs.jquery.com/Tutorials) section

Filed under: Technology

A (First) day with my son, alone at home

MY wife had to go out for some reason, so I got a first day with my son alone at home. We dropped my wife and came back. Now story start from here.

I asked to my son what he want to do now, I suggested him to take bath I will keep his milk ready.

Now questions are like:

  • How milk he needs?
  • How much warm it should be?
  • What else he need with milk?
  • How much cereal he needs in milk?
  • Where are his clothes?
  • Which clothes he supposed to put on?

Now lunch time, Again list of Questions:

  • Where are plates and spoons?
  • How much my son need and how much warm it should be for him?
  • Etc., Etc., Etc.,

Oh. How many small points she takes care every day, I never realized before.

Quote from me today:
“She takes care of my home, my son and me, because of that I can go out and earn money to run my home. She does equal job as I do, may be more than that, she does it with love”

Filed under: Personal

May 2017
M T W T F S S
« Oct    
1234567
891011121314
15161718192021
22232425262728
293031  

My Twitter

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

del.icio.us bookmarks

Blog Stats

  • 22,973 hits

Flickr Photos

More Photos