Q:

Attaches a change event to the select element (Use to create a drop-down list.) using jquery

0

Attaches a change event to the select element (Use to create a drop-down list.) that gets the text for each selected option and writes them in a paragraph  using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Attaches a change event to the select element (Use to create a drop-down list.) that gets the text for each selected option and writes them in a paragraph.</title>
</head>
<body>
<select name="colors" multiple="multiple">
<option selected="selected">Red</option>
<option selected="selected">Green</option>
<option>Blue</option>
<option>Orange</option>
<option>Black</option>
<option>White</option>
</select>
<p></p>
</body>
</html>

JavaScript Code :

// A sample function f1 
var foo = function( value ) {
  console.log( "foo: " + value );
};

var callbacks = $.Callbacks();
 
$( "select" )
.change(function () {
var str = "";
$( "select option:selected" ).each(function() {
str += $( this ).text() + " ";
});
$( "p" ).text("Selected Colors: "+str) .css( "color", "blue" );
})
.change();

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now