id가 없는 canvas 찾아서 id 셋팅하기

2021. 1. 23. 22:24Javascript/jQuery

 

<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="./js/tiff.min.js"></script>
<script type='text/javascript'>
		function get() {
        var temp = $('#temp')
        console.log(temp[0].id);
        temp.attr('id','weather')
        console.log(temp[0].id)

        var temp = $('canvas')[4]
        //var temp = $('canvas').get(4)
        //var temp = document.getElementsByTagName('canvas')[4];
        var temp = document.getElementsByTagName('canvas')[4];
        console.log(temp)
        temp.setAttribute('id','weather2')
        console.log(temp.id)
    }
</script>
<body onload='draw();'>
    <input type='button' value='확대' onclick='large();'>
    <input type='button' value='Canvas' onclick='get();'>
    <canvas id="tutorial" width='150' height='150'></canvas>
    </canvas>

    <canvas id="temp" width='150' height='250'></canvas>
    </canvas>

    <canvas id="stockGraph" width='150' height='150'>
        current stock price: $3.15 +0.15
    </canvas>

    <canvas id='clock' width='150' height='150'>
    </canvas>

    <img src='./a.png' width='150' height='150' alt='aaaaa'>    
</body>

 

'Javascript > jQuery' 카테고리의 다른 글

HTML 태그 삭제  (0) 2021.01.24
canvas getContext 인식  (0) 2021.01.24
API 참조 방법  (0) 2021.01.23
json 처리  (0) 2021.01.17
최신 버전 가져오기  (0) 2021.01.16