Saber Amani
Saber Amani

Reputation: 6489

Change html element's attribute inside html-script

let's say I have a mark-up like this:

<script>
    var doSomething = function () {
        var container = $('.container');
        var list = $('#result-list');
        list.find('.result').attr('id', 'x');
        container.append(list.html());
    };
</script>

<script type="text/html" id="result-list">
    <div class="result"></div>
</script>

<a href="#" onclick="doSomething();">DO</a>
<div class="container">

</div>

I can't change div id attribute which is placed inside html-script. I don't know what or where is the problem. Any advice will be helpful.

Upvotes: 2

Views: 365

Answers (2)

Rakesh Kumar
Rakesh Kumar

Reputation: 2865

Are you looking for this.

var doSomething = function () {
    var container = $('.container');
    var list = $('#result-list');
    container.append(list.html());
     container.find('.result').attr('id','x');
};

Demo

Upvotes: 2

jingyinggong
jingyinggong

Reputation: 646

<script>
    var doSomething = function () {
        var container = $('.container');
        var list = $('#result-list');
        var $result = $(list.html());
        $result.attr('id','x');
        container.append($result);
    };
</script>

Upvotes: 1

Related Questions