javascript - 如何获取兄弟元素的内部html文本
问题描述
为什么这不打印出跨度的文本“Apple”?
<label class="search-recipe-chkbox fruitLabel">
<input type="checkbox" class="checkbox check-box-mob-filters check-box-desktop" id="12DSKT" name="Apple" value="12">
<span class="checkmark"></span>
<span class="ingredient-label">Apple <span class="recipe-count" id="12numDSKT">(1)</span></span>
</label>
for (var checkbox of checkboxes) {
if (checkbox.checked == true) {
console.log($(checkbox.id).siblings('.ingredient-label').text());
}
}
checkboxes
只是表单中的所有复选框(输入),并且已选中 Apple。
谢谢
解决方案
您也可以使用 -console.log($("[id]").siblings('.ingredient-label').text());
推荐阅读
- python - 尝试在 AWS Lambda 上测试 Scrapy Web-Crawler 时出现此错误“raise error.reactornotrestartable()”
- javascript - 从 Angular 中的 API 获取数据时出现问题
- powershell - 如何使用powershell查找和替换文本文件中第6次出现管道字符后出现的字符串
- linux - 如何在 Ubuntu 中检查交换分区
- python - 杀死从 shell 脚本调用的脚本启动的所有进程
- .net - 为什么 Guid.NewGuid 总是在同一个位置有一个 4?
- database - MongoDB 4.2 更新管道。查询:嵌套数组中的“推送或更新”
- python-3.7 - 如何从进一步计算中排除列表的某些元素
- html - list-style-image: url('imageurl') 不在网页上显示图片
- discord.js - Discord.js 事件更新存在垃圾邮件