What does this statement means in javascript?

i am not able to understand this statement. i already tired on google but this is showing up just as an example

$('#myDiv a:first').attr({
    href : 'newDestination.html',
    rel : 'super-special'

Answers 1

  • Its sets the attribute to a DOM element using attr method of jquery.

    In your example, you are setting href and rel attribute to an element which is matching the selector '#myDiv a:first'.

    '#myDiv a:first'

    It means if there is a div with an id myDiv, it will take its first child element which is an anchor (a) and apply these attributes to it.

Related Articles