Which code segment should you add to the webpage?

You develop an HTML5 webpage. You have the following HTML markup:

You need to change the background color for all of the elements whose name attribute ends with the word
name.
Which code segment should you add to the webpage?

You develop an HTML5 webpage. You have the following HTML markup:

You need to change the background color for all of the elements whose name attribute ends with the word
name.
Which code segment should you add to the webpage?

A.
$ (‘input [name!=”name”]’) .css ({ ‘background-color’ : ‘ #E0ECF8’}) ;

B.
${‘input [name=”~name”] ‘) .css ({ ‘background-color’ : ‘ #E0ECF8’ }) ;

C.
${‘input[name=”*name”]’).css({‘background=color’: #E0ECF8′});

D.
$( ‘input [name=”$name”] ‘) .css ({ ‘background-color’ : ‘#E0ECF8’});

Explanation:
The string pattern “*name” matches all strings that ends with name.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Mkool

Mkool

both C and D are correct

Mkool

Mkool

Correction: Correct Answer is D.

Although C works on this scenario it is not the correct jquery selector to use when, we want to match the end of the attribute value. as it is requested in this question.
https://api.jquery.com/attribute-contains-selector/

Andi

Andi

I think it should be something like:
$(“input[name$=’name’]”).css({‘background-color’: ‘#E0ECF8’});

KT

KT

Yes. Your answer is correct.