Id selector

Page operations are node support, developers need to quickly find the specified node,

There are two ways to get node objects by id: (1) through ** native method ** document.getelementById (” specify id “); Object. Style. Property = xx; Assign a value to an attribute. $(” select id “); $(” select id “); Get JQuery object, use object.css (‘ properties’, ‘assignment’);

The following three divs, two of which have the same ID, get JQuery object through JQuery selector, cannot be set.

Handled through native javascript methods

<script type="text/javascript"> var div = document.getElementById("aaron"); Div. Style. border = "3px solid blue"; </script>Copy the code

#imooc = ‘#imooc’; #imooc = ‘#imooc’;

<script type="text/javascript">
        $('#imooc').css('border', '5px solid red');
    </script>
Copy the code

Ids are unique, and each ID value can only be used once on a page. If multiple elements are assigned the same ID, only the first DOM element in the selection set of that ID will be matched. But that shouldn't happen; Pages with more than one element using the same ID are not validCopy the code
<! PUBLIC DOCTYPE HTML "- / / / / W3C DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd" > < HTML > < head > < meta  http-equiv="Content-Type" content="text/html; Charset = utf-8 "> < script SRC =" http://libs.baidu.com/jquery/1.9.1/jquery.min.js "> < / script > < title > Insert the title here</title> <style> div{ width: 100px; height: 90px; float: float; padding: 5px; margin: 5px; background-color: #eeeeee; } < / style > < / head > < body > < div id = "Aaron" > < p > id = "Aaron" < / p > < p > select < / p > < / div > < div id = "imooc" > < p > id = "imooc < / p >" < p > JQuery selected < / p > < / div > < div id = "imooc" > < p > id = "imooc" < / p > < p > JQuery uncheck < / p > < / div > <! <script type="text/javascript"> var div = document.getelementById (" Aaron "); Div. Style. border = "3px solid blue"; </script> <script type="text/javascript"> $('imooc').css('border', '5px solid red'); </script> </body> </html>Copy the code