jQuery select by ID allows you to find a specific HTML element with the value of its attribute – “id”. You can select and do the intended action on an element by making its id unique.

jQuery按ID选择可以让您找到具有其属性值“ ID”的特定HTML元素。 您可以通过使元素的ID唯一来选择元素并对其执行预期的操作。

jQuery按ID选择 (jQuery select by ID)

Here is the general syntax for using the jQuery select by id:

这是使用jQuery按ID选择的一般语法:

$(“# ID”)

$(“#ID”)

ID could be any value provided in the id attributes of the HTML element. You should use # followed by its ID in the selector.

ID可以是HTML元素的id属性中提供的任何值。 您应该在选择器中使用#后跟ID。

For example, if there is a HTML element in the document like <div id=”text”> some text </div>, $(“#text”) will select the div with id equal to ‘text’ and do the intended action on it.

例如,如果文档中有一个HTML元素,例如<div id =“ text”>一些文本</ div>,则$(“#text”)将选择id等于“ text”的div并执行预期的操作对其采取行动。

The main importance of this jquery selector is we will get separate control over each element by its unique id and the manipulations will affect only that element.

这个jquery选择器的主要重要性是我们将通过其唯一ID对每个元素进行单独控制,并且操作将仅影响该元素。

jQuery按ID选择示例 (jQuery Select by ID Example)

This example demonstrates the use of jQuery select by id and changing the CSS style of the selected element.

此示例演示了如何通过id使用jQuery select以及如何更改选定元素CSS样式。

<html>
<head>
<title>jQuery select by ID</title><style>
div {
width: 80px;
height: 80px;
float: left;
padding: 10px;
margin: 10px;
background-color: #eee;
}
</style><script src="//code.jquery.com/jquery-3.2.1.min.js"></script></head>
<body>
<div id="div1"><p>id="div1"</p></div>
<div id="div2"><p>id="div2"</p></div>
<script>
$( "#div1" ).css( "border", "5px solid green" );
</script>
</body>
</html>

In this example you can see that <div> element with id=’div1′ is selected for manipulation.

在此示例中,您可以看到选择了id ='div1'的<div>元素进行操作。

Above HTML produces output as shown in below image.

上面HTML产生输出,如下图所示。

jQuery按ID选择摘要 (jQuery select by id summary)

Every HTML element can have unique id attribute. Therefore, it’s easy to get control over the element using the jQuery select by ID.

每个HTML元素都可以具有唯一的id属性。 因此,很容易使用jQuery select by ID来控制元素。

We can use this selector whenever we want to access a specific element to execute some task. Using this selector in combination could enhance the flexibility as well.

每当我们要访问特定元素以执行某些任务时,都可以使用此选择器。 组合使用此选择器也可以增强灵活性。

翻译自: https://www.journaldev.com/4549/jquery-select-id

jQuery按ID选择相关推荐

  1. jquery按名称选择_jQuery按名称选择

    jquery按名称选择 jQuery select by name or jQuery element selector allows us to find all HTML elements wit ...

  2. 如何使用jQuery按名称选择元素?

    本文翻译自:How can I select an element by name with jQuery? Have a table column I'm trying to expand and ...

  3. jQuery获取Select选择的Text和 Value(转)

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...});   //为 ...

  4. jQuery取得select选择的文本与值

    jquery获取select选择的文本与值 获取select : 获取select 选中的 text :   $("#ddlregtype").find("option: ...

  5. jQuery获取Select选择的Text和 Value

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...

  6. jquery选择器连续选择_JQuery中的选择器

    jquery选择器连续选择 It's time to write some JQuery now. Do check out the introductory article on JQuery fi ...

  7. jquery按名称选择_jQuery按类别选择

    jquery按名称选择 jQuery select by class name allows us to find a specific HTML element with the value of ...

  8. jQuery根据ID、CLASS、等获取对象

     jQuery根据ID.CLASS.等获取对象 Jquery是继prototype之后又一个优秀的Javascrīpt框架.它是轻量级的js库(压缩后只有21k) , 它兼容CSS3,还兼容各种浏览器 ...

  9. [你必须知道的css系列]第一回:丰富的利器:CSS选择符之通配符、类选择符、包含选择符、ID选择符...

    一般没有系统的学习过,只是在网上看一些片断教程的人.见到最多的可能也就是: 元素选择符(例如:body .a .li ) ID选择符(例如:#head.#body.#foot) 类选择符(例如:.re ...

最新文章

  1. 2018.3.31 设计模式之生成器模式详解及例子(对象创建型模式)
  2. ES6实现一些常见算法
  3. AFIO时钟何时开启
  4. Angular依赖注入机制的一个错误消息:Error Cannot instantiate cyclic dependency!
  5. 计算机组装维修中级试题,计算机维修工中级理论知识试卷.doc
  6. JAVA自定义Mybatis注解
  7. 通过UDR扩展GBase8s查询行为的工程实践
  8. “和合信诺”获启赋资本数千万元Pre-A轮融资-专注监管科技、助力金融业落地监管合规最后一公里
  9. 关闭Window 10 Ctrl+Shift+B(表情包)快捷键冲突
  10. Echarts 横坐标时间轴,相同的年份只显示第一个,方案记录
  11. win10-SW2016工程图关联零件属性链接操作
  12. 惨遭腾讯面试官吊打高并发系统设计,回来学习2400小时后成功复仇!
  13. classes in c++
  14. 图像检索|经典论文阅读|快速入门|综述学习
  15. 5.11 使用新建填充图层制作艺术效果 [原创Ps教程]
  16. 每粒尘埃都有IP,你信了吗?
  17. Android App修改字体大小,且不随系统字体大小更改
  18. 如何用在自己的网页中嵌入腾讯视频网页播放器播放一些文件
  19. 手握多样算力,从容面对下一代互联网的百样创新
  20. BuddyPress汉化中文语言包 BuddyPress汉化教程步骤

热门文章

  1. [转载] Python杂记之 list.clear()方法,清空列表
  2. AJAX通过HTML请求C#一般处理程序
  3. maven 项目 spring mvc + jdbc 配置文件
  4. AsyncTask使用须知
  5. 简单的二维数组问题,不用不知道,一用吓一跳
  6. 卡巴斯基宣布高端静谧岑寂僻静产物PURE
  7. (转自dflying chen)使用Anthem.NET 1.5中的FileUpload控件实现Ajax方式的文件上传
  8. PAD-Net: Multi-Tasks Guided Prediction-and-Distillation Network for Simultaneous Depth Estimation an
  9. 数据结构上机实践第八周项目6- 猴子选大王(数组版)
  10. PIL Error, TypeError: Cannot handle this data type:(1, 1), <i8