How to set attribute of any element in jquery

Sometimes it becomes our requirement to set the attribute of any element using jquery. For instance, in my next tutorial i will teach you how to set the alt attribute of images that doesn't contain the alt attribute. Its very easy in jquery by using its attr() function which is built-in in jquery.Let's have a look over the example given below.
How to set attribute of any element in jquery

  <script src=""></script>
<style type="text/css">
	<div id="myDiv">Welcome to</div><br/>
<script language="javascript" type="text/javascript">
$("#myDiv").attr('class', 'divclass');

Welcome to

In the above mentioned code snippet i have decalred a css class which is divclass and then by using built-in attr() function of jquery i assigned divclass to the div having id of myDiv. Using this behavior of attr() function we can set one or more attributes for the set of matched elements.

So that's it.

I love your feedback.