<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="http://code.jquery.com/jquery-1.11.3.js"></script>
<script>
function create ( where, tag, id, value ) {
var valueField = " value = '" + value + "'",
condition = typeof ( value ) === 'undefined';
alert ( condition );
if ( condition ) valueField = "";
alert ( valueField );
$ ( where ).append ( "<" + tag + " id = '" + id + "'" + valueField + "'></" + tag + ">" );
}
create ( "body", "div", "field" );
create ( "#field", "textarea", "text" );
create ( "#field", "button", "zolotoyBaton", "OK" );
</script>
</body>
<html>
Результат:
<div id="field" '=""><textarea id="text" '=""></textarea><button id="zolotoyBaton" value="OK" '=""></button></div>
Вопрос: откуда взялось '="" в каждом теге?