---
title: "How do you select an item using css class or ID and get the value by use of jquery"  
description: "How do you select an item using css class or ID and get the value by use of jquery"  
author: "Anonymous User"  
published: 2011-05-20  
updated: 2020-09-18  
canonical: https://www.mindstick.com/interview/978/how-do-you-select-an-item-using-css-class-or-id-and-get-the-value-by-use-of-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# How do you select an item using css class or ID and get the value by use of jquery

If an element of html like < div> , < p> or any tag have ID MyId and class used MyClass then we select the element by below jquery code\
\
$('#MyId') for ID and for classs $('.MyClass') and for value\
\
var myValue = $('#MyId').val(); // get the value in var Myvalue by id \
Or for set the value in selected item \
\
$('#MyId').val("print me"); // set the value of a form input

## Answers

### Answer by Anonymous User

If an element of html like < div> , < p> or any tag have ID MyId and class used MyClass then we select the element by below jquery code\
\
$('#MyId') for ID and for classs $('.MyClass') and for value\
\
var myValue = $('#MyId').val(); // get the value in var Myvalue by id \
Or for set the value in selected item \
\
$('#MyId').val("print me"); // set the value of a form input


---

Original Source: https://www.mindstick.com/interview/978/how-do-you-select-an-item-using-css-class-or-id-and-get-the-value-by-use-of-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
