ARTICLE

Handle Control's Attribute Using jQuery

Posted by Abhimanyu K Vatsa Articles | JQuery April 28, 2012
This article shows how to handle or target a control's attribute using jQuery.
Reader Level:

Introduction

This article shows how to handle or target a control's attribute using jQuery. We already talked about how to modify the appearance of controls in a web page when user hovers the mouse or clicks the mouse. For this we used .addClass(), .removeClass(), .css(), .toggleClass() etc. I'm going to cover some cool stuff using a problem and solution approach. So, let's start looking at first problem.

Problem 1

If you simply want to open all URLs on a new tab, a quick jQuery code can do this using .attr() method.

Note: For more read this.

.attr() Method

.attr() gets the value of an attribute for the first element in the set of matched elements.

Problem 2

If you have a website that uses a huge list of images and you forgot to place alt (alternative) text (for when an image is not found, that will be displayed), how to fix this. I mean how you will add a brand new attribute to an existing list of controls? Don't worry, here is the fix.

image001.jpg

Look at the result in the browser.

image002.jpg


In the same way you can handle attributes of any control.

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
HTML 5 + JQUERY CONTROLS
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
HTML 5 + JQUERY CONTROLS