jquery id selector code example

Example 1: jquery get element id

$(this).attr('id')

Example 2: jquery get element by id

<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>

Example 3: get element by id in Jquery

$("#YourElementId").val();

Example 4: get element by id jqueryt

$( "#myDiv" )

Example 5: jquery select

$('#selector').selectmenu();

Example 6: id in class selector jquery

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

Tags: