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.
WRONG! the selector must look like that:
$( ‘input [name$=”name”] ‘) .css ({ ‘background-color’ : ‘#E0ECF8’});
D is the correct option
The answer are wrong, the correct code should be $(‘input[name*=”name”]’).css({‘background-color’:’#E0ECF8′});
But the following code is correct too.
$(‘input[name$=”name”]’).css({‘background-color’:’#E0ECF8′});
D