Skip to main content

Posts

Showing posts with the label attributes

Can't set / change CSS background image with jQuery problem solution

Hello everyone. I’ve been busy lately with some projects and could not write much on “jQuery HowTo” blog. So, when I came across this little problem, I thought I would share it with you. Anyway, I was working on one of my projects and I needed to set a background image using jQuery on some div. At first my background setting code looked like this: $('#myDiv').css('background-image', '

Can't set / change CSS background image with jQuery problem solution

Hello everyone. I’ve been busy lately with some projects and could not write much on “jQuery HowTo” blog. So, when I came across this little problem, I thought I would share it with you. Anyway, I was working on one of my projects and I needed to set a background image using jQuery on some div. At first my background setting code looked like this: $('#myDiv').css('background-image', '

Identifying & locating mouse position in jQuery

While writing the next jQuery tutorial I needed to identify and locate where the mouse was on the page. Tracking mouse position on the page with jQuery is easy. You don’t need to check what browser the script is running like it is used to be with plain JavaScript. To identify where the mouse is in jQuery all you have to do is to read event object’s .pageX and .pageY properties. Example: $().

Identifying & locating mouse position in jQuery

While writing the next jQuery tutorial I needed to identify and locate where the mouse was on the page. Tracking mouse position on the page with jQuery is easy. You don’t need to check what browser the script is running like it is used to be with plain JavaScript. To identify where the mouse is in jQuery all you have to do is to read event object’s .pageX and .pageY properties. Example: $().

Disable submit button on form submit

Form submission is one of the most used actions and double form submission is one of most occurred problems in web development. Rather than dealing with this problem server side, eating up your CPU process time, it is much easier and better to deal with this problem client side using JavaScript. When we talk javascript, what it a better way to write it other than using jQuery?! So this Friday’s

Disable submit button on form submit

Form submission is one of the most used actions and double form submission is one of most occurred problems in web development. Rather than dealing with this problem server side, eating up your CPU process time, it is much easier and better to deal with this problem client side using JavaScript. When we talk javascript, what it a better way to write it other than using jQuery?! So this Friday’s

jQuery image swap or How to replace an image with another one using jQuery

Swapping one image with another is probably one of the most used javascript techniques. Also Dreamweaver made “image replacement” even easier for non HTML/Javascript programmers by including this feature out of the box. One thing about Dreamweaver’s image swapping javascript is that it’s not the most beautiful javascript code. Well, as always with anything javascript related, jQuery is to the

jQuery image swap or How to replace an image with another one using jQuery

Swapping one image with another is probably one of the most used javascript techniques. Also Dreamweaver made “image replacement” even easier for non HTML/Javascript programmers by including this feature out of the box. One thing about Dreamweaver’s image swapping javascript is that it’s not the most beautiful javascript code. Well, as always with anything javascript related, jQuery is to the

How to disable/enable an element with jQuery

Sometimes you need to disable or enable some elements in your document and jQuery makes this task easy. All you have to do is to set disabled attribute to "disabled". Example: // To disable $('.someElement').attr('disabled', 'disabled'); In order to enable any disabled element you need to set the disabled attribute to empty string or remove it entirely like in the code below. // To enable

How to disable/enable an element with jQuery

Sometimes you need to disable or enable some elements in your document and jQuery makes this task easy. All you have to do is to set disabled attribute to "disabled". Example: // To disable $('.someElement').attr('disabled', 'disabled'); In order to enable any disabled element you need to set the disabled attribute to empty string or remove it entirely like in the code below. // To enable

How to check if checkbox is checked using jQuery

Note: If you are new to jQuery, you might find our short jQuery beginner tutorials useful. While working on my previous project I needed a way to check if the certain checkbox is checked or not. jQuery is a great library but I had a hard time identifying if any particular checkbox was checked. So here is the way to do just that. All you need to do is to check checked attribute of checkbox HTML

How to check if checkbox is checked using jQuery

Note: If you are new to jQuery, you might find our short jQuery beginner tutorials useful. While working on my previous project I needed a way to check if the certain checkbox is checked or not. jQuery is a great library but I had a hard time identifying if any particular checkbox was checked. So here is the way to do just that. All you need to do is to check checked attribute of checkbox HTML

How many elements were selected by jQuery

Recently I needed to find out how many elements were selected by jQuery. jQuery selector returns an array of elements jQuery object that has .length attribute. So the easiest way is to get the length of returned jQuery object. The size of that object will be equal to the number of selected elements. $('.someClass').length; // Assume you have 4 .class elements $('.class').length; // would return

How many elements were selected by jQuery

Recently I needed to find out how many elements were selected by jQuery. jQuery selector returns an array of elements jQuery object that has .length attribute. So the easiest way is to get the length of returned jQuery object. The size of that object will be equal to the number of selected elements. $('.someClass').length; // Assume you have 4 .class elements $('.class').length; // would return

Set HTML tag’s / element’s attribute

In our previous post about “How to get an element’s / tag’s attribute” I described how to get element’s attribute. In this post I would like to show you how to set any HTML tag’s or element’s attributes. Don’t forget, jQuery can set any attributes like id, class, style, name, title, etc. Setting element’s attribute example: // This code add title to all page links $("a").attr("title", "This is

Set HTML tag’s / element’s attribute

In our previous post about “How to get an element’s / tag’s attribute” I described how to get element’s attribute. In this post I would like to show you how to set any HTML tag’s or element’s attributes. Don’t forget, jQuery can set any attributes like id, class, style, name, title, etc. Setting element’s attribute example: // This code add title to all page links $("a").attr("title", "This is