Jan
0
Q:

get element by id in Jquery

$(this).attr('id')
5
var myId = $(this).attr('id');
alert( myId );
2
alert($(this).attr('id'))
4
var myId = $("#test").prop("id");
1
<script>
$(document).ready(function(){
    $("#myBtn").click(function(){
        var elmId = $("#test").attr("id");
        alert(elmId);
    });
});
</script>

<body>
    <div id="testDiv">Data of the Div</div>
    <br>
    <button type="button" id="myBtn">Show Div ID</button>
</body>
3
$("#YourElementId").val();
2
$( "#myDiv" )
3

New to Communities?

Join the community