Handle Controls Attribute using jQuery


Introduction

This post shows how to handle or target controls attribute using jQuery. We already talked how to modify the appearance of controls on web page when user, hover the mouse or click the mouse. For this we used .addClass(),.removeClass(),.css(), .toggleClass() etc.

I'm going to cover some cool stuffs using problem to solution approach. So, let's start and look at first problem.

Problem 1

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


.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 huge list of images there and forgot to place alt (alternative) text (when image not found, that will be displayed), how to fix this. I mean how you will add a brand new attribute to existing list of controls?
Don't worry, here it the fix.


Look at result in browser.


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

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System