LearnFast.Ninja

jQuery get element by id value

Tutorial that show you how to use jQuery for getting id by value. This is the syntax for the getElementById function using jQuery. Write function that get element by id value then draw a border around it. Execute the function on page load. Try the following Working example.

Step 1: This is the syntax for the getElementById function using jQuery. 

$("#First");

 
Step 2: Write function that get element by id value then draw a border around it. 

function Draw_Border() {

    $("#Second").css("border", "1px solid #c0c0c0");

}

 
Step 3: Execute the function on page load. 
$("document").ready(Draw_Border);
 
Working example: 

<html>

<head>

    <title>get element by id value</title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script>

 

    <script type="text/javascript">

        $("document").ready(Draw_Border);

 

        function Draw_Border() {

            $("#Second").css("border", "1px solid #c0c0c0");

        }

    </script>

</head>

<body>

    <div id="First">I am first div</div>

    <div id="Second">I am second div</div>

</body>

</html> 
 
Result: 


Tags

jquery

jquery-tutorial-for-beginners jquery-select-element