Jquery Post

Contains common Jquery code

* Display jQuery version

alert(jQuery.fn.jquery);

* Find how many check boxes have been checked

var count = $(‘input[type=checkbox]:checked’).length;

* Get ID, class of an element

var element_id = $(this).attr(‘id’); or element_id = this.id;
var class = $(this).attr(‘class’); or class = this.class;

* Set the attribute of an element

$(this).attr(‘class’, ‘new-class’);
$(this).attr(‘title’, ‘new-title’);

* Set multiple attributes for an element

$(‘this’).attr({
class: ‘new-class’,
title: ‘new-title’
});

* Checking and Un-checking a check-box

this.checked = false; //un-check
this.checked = true; //check

* Loop through all check-boxes and find if they are checked

$(‘input[type=checkbox]’).each(function () {
var is_checked = (this.checked ? “1” : “0”);
});

* Loop through all radio buttons in a form

$(“#form-id”).find(‘:radio’).each(function() {
radio_id = $(this).attr(‘id’);
radio_name = $(this).attr(‘name’);
});

* PHP like explode and implode functions in Javascript

//explode
var my_string = “abc-def-ghi-jkl”;
var my_array = [];
my_array = my_string.split(“-“);

//implode
var my_array = new Array(‘abc’, ‘def’, ‘ghi’, ‘jkl’);
var my_string = “”;
my_string = my_array.join(“-“);

# Disable all radios of a group

$(‘input:radio[name=radio-group-name]’).attr(‘disabled’, true);

# Get the value of the selected radio button in a group

$(‘input:radio[name=radio-group-name]’).val();

# Disable all input elements in a form (input, textarea, select and button)

$(“#form-id :input”).attr(“disabled”, true);

# Disable only input elements of a form

$(“#form-id input”).attr(“disabled”, true);

# Get the current page url

var current_page_url = window.location.pathname;

Advertisements

Go on, be positive!

The state of your mental health says a lot about your life. Experts say that people who focus more on positive thinking and have positive attitudesnot only enjoy life more but also lead healthier lives. Optimists are said to deal with pain and hardship better than their pessimistic counterparts. Remember your body reacts to your thoughts, feelings and actions. So if you’re in a bad mood, your body will respond in a similar manner. While keeping yourself fit by eating right and managing stress is alright, positive thinking goes a long way in ensuring good health. 

If you’re feeling unwell and tell yourself that you’re coming down with a bug, chances are that it will come true. Your mind is more powerful than you think. Stop thinking that you are going to fall sick or will take time to recover from a sickness. Experts call this the placebo effect – a placebo is treatment that provides whatsoever no medical gain except making the patient believe that it is helping them get better. Several patients report relief from their problems although they haven’t actually received any medicine. 

Thinking positive may not come naturally to everyone. To make that change you need to make a conscious effort. Whenever you find yourself getting negative thoughts, stop them. Start thinking of a happy event or memory that will cheer you. 

Make positive statements. Instead of thinking or saying, “I can’t do this or this is impossible”, state positive affirmations – I will give this my best shot or I have so many things to be grateful about,” sends out positive vibes. 

Down in the dumps or feeling out of sorts with an illness? Visualisation is a great technique that will actually help you feel better. Imagine yourself healthy and happy. When you visualise your thoughts, they send out positive signals to your brain making you feel better. 

Positive emotions like humour, friendship and love are known to supercharge your health. Experts have long since asserted that laughter is great for you. Life is full of humour if you stop and experience it. Watch funny movies or TV shows, read books and jokes that make you smile, meet people who make you laugh. Laughter increases creativity, reduces pain, and even accelerates healing. 

Catch up with friends. With the hectic lives we lead, we often forget how relaxing and calming meeting a friend can be. Good friendships are important so make sure you surround yourself with genuine ones. Having close buddies help you recuperate faster from sickness. 

Social service and volunteering boosts feelings of compassion, which in turn make you a better person. When you help someone, you also help yourself. There are several orphanages, old age homes, mentally and physically challenged centres and animal shelters that need you to spend time with people and animals living there. You don’t need to go there every week. Go once in a while and notice the difference. 

When you spend a certain amount of time in prayer, and spiritual beliefs, you send positive vibrations your side. Have faith and it will go a long way in being a faithful companion. Prayer and meditation are good ways to connect to your spiritual side. 

Life lessons from a glass of water!

Not worrying too much about the problem is the first step to solve it.

A chemistry professor decided to teach his students a different lesson one day. Holding a glass of water in his hand, he asked the students, “How much do you think this glass of water weighs?” “500 grams!” came a voice from the back. “600,” said another student. “I don’t really know!” said the professor, holding the glass up to make sure everyone could see it. “And unless we weigh it, we won’t know.” With the glass still in his outstretched hand, the professor continued, “What will happen if I hold it like this for a few minutes?”

“Nothing!” came the reply. “Right, and if I hold it for an hour like this, what might happen?” “Your hand will begin to hurt,” said a student. “Indeed. And what would happen if I held the glass in my hand like this for 24 hours?”

“You would be in tremendous pain,” said one student. “Your hand will probably go numb,” said another. “Your arm will be paralysed and we’ll need to rush you to the hospital!” said a student on the last bench.

“True,” said the professor. “But notice that through all this, the weight of the glass did not change. What then causes the pain?”

The class went quiet. The students seemed puzzled.“What should I do to avoid the pain?” asked the professor. “Put the glass down!” said a student.

“Well said!” exclaimed the professor. “And that’s a lesson I want you to remember. The problems and worries in life are like that glass of water. Think about them for a while and nothing happens. But think about it a bit longer and they begin to hurt. And if you think about them all day long, you will feel paralysed – incapable of doing anything. It’s important to remember to let go of your problems. Remember to put the glass down!”

We may not have been in that classroom that day, but it’s a lesson we would all do well to remember. Put the glass down! Always. It’s not just problems and worries. Sometimes, we feel hurt and betrayed by a friend. And we carry that grudge through our lives. It grows and causes us anguish and pain. Learning to forgive – and forget – is not just good for the other people, it’s great for you. Nelson Mandela spent 27 years in jail and when he was finally freed, you can understand how angry and vengeful he must have felt. But guess what? When he became President, he invited his jailers to be present at the inauguration – in the VIP seats! If he could forgive after 27 years of suffering, surely we can too.
It is the same with our fears too. A failure or an incident in early childhood becomes a deeply entrenched fear over time. Fear of public speaking, fear of Maths, fear of rejection. You name it, and chances are, we have it. Someone gave us that glass to hold when we were little kids – ‘you are clumsy, you are no good, you can’t do it’ – and we have faithfully held on to it all our lives. ‘I can’t’ – becomes a thought that stays in our mind and grows – leading us to complete paralysis. Time to put the glass down!

The story goes that there was a hardworking man who lived a contented life with his wife and children. Every evening when he returned from work, he’d follow a ritual. Outside the door to his house were three nails. On the first one, he’d put his hat. On the second he’d hang his coat. And on the third nail, he’d unwrap an imaginary turban from his head and ‘put’ it there. A friend happened to see this and enquired what he was putting on the third nail every day.

“Those are my problems, my worries and my anger,” said the man. “I have lots of that at work, but when I come home, I remember to take it off – and leave them outside. I don’t take them home with me.” Maybe you should learn to do that too. Starting today. Put the glass down. And see the difference!

Prakash Iyer is MD, Kimberly-Clark Lever and Executive Coach. For more inspiring life lessons, read Mr Iyer’s new book The Habit of Winning.