How to change the value of an object when clicked?

Im populating / inserting jsonObjects[i].typein menuwith divcalled #changetotypes. Im getting the values r, cand efrom jsonObjects[i].typethe menu, I know that I want to click on the value r, cand eand change the values ​​on pressing cost. Know that I can click on an object and display the value r, cor e. Therefore, if I click on an object, it gets / displays the value jsonObjects[i].type r, cor ein the menu that the object has. Know how I can change the example of the value of clicks on an object from rto c?

<li>
    <a href="#">Typs</a>
        <ul>
            <li>
                <a href="#"><span id="currenttype" title=""></span></a>
                <ul id="changetotypes"></ul>
            </li>
        </ul>
</li>

function populateTypes() {

    for(i = 0; i < jsonObjects.length; i++) {

        if(availableTypes.indexOf(jsonObjects[i].type) < 0) {

            availableTypes.push(jsonObjects[i].type);
            $("#changetotypes").append('<li><a href="#">' + jsonObjects[i].type + '</a></li>');
        }
    }
}
+4
2

- (jsFiddle). , jsonObjects - .

function populateTypes() {
    var availableTypes = [];
    for(var i = 0; i < jsonObjects.length; i++) {
        if(availableTypes.indexOf(jsonObjects[i].type) < 0) {
            availableTypes.push(jsonObjects[i].type);
            $('<li><a href="#">' + jsonObjects[i].type + '</a></li>')
            .data('type', jsonObjects[i].type)
            .on('click', function(){ $('#currenttype').text($(this).data('type')); })
            .appendTo('#changetotypes');
        }
    }
}

, < li/ > , currenttype.

, currenttype, < li/ > , , , , ( . ) < a/ > ( $('a', $(this)). text()).

0

click #changetotypes children's, html .

, , , .

, .

0

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


All Articles