Inspect item in Chrome without displaying the selected option

When I use the Chrome Inspect Element function to view the item <select>that I programmatically set for the selected parameter, the selected one <option>does not show selected="selected". Everything works correctly, I just don’t see which parameters are selected in the inspector’s view.

Is this the right behavior? It seems that not only should the selected item be selected in the internal DOM representation, but should also be added selected="selected"to the visual representation.

This example uses several different ways to set a property selectedfor <option>: http://jsfiddle.net/ScTTY/

Essentially, I am using variations of this code:

    var current = new Date().getFullYear();
    var year1 = this.$("select.year1");
    for (var i=0; i<100; i++) {
        var option = $("<option>",{
            value: current - i,
            text: current - i,
            selected: (i==17 ? "selected" : "")
        });
        year1.append(option);
    }

However, I use different configuration methods selected:

        selected: (i==17 ? true : false)

        if (i==17) option.attr("selected","selected");

        if (i==17) option[0].selected = true;

        if (i==17) option[0].selected = "selected";

<select>, 1912 2011 1994 .

+3
1

"" . "" "". , , .

, - HTML. , Firebug, .

+1

Source: https://habr.com/ru/post/1791880/


All Articles