Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript td前的前置图标,将用.html()更改_Javascript_Jquery_Html_Css_Font Awesome - Fatal编程技术网

Javascript td前的前置图标,将用.html()更改

Javascript td前的前置图标,将用.html()更改,javascript,jquery,html,css,font-awesome,Javascript,Jquery,Html,Css,Font Awesome,我有需要更改其值的tds。这样做时: $(".class td:nth-child(2)").html("new value"); 但我尝试在该值之前添加字体图标: $(".class td:nth-child(2)").append("<i class=\"fa fa-arrow-up\"></i>"); $(“.td类:第n个子项(2)”)。追加(“”); 它将图标放在html之后。我希望它在html之前。看起来我需要追加,因为html清除了类信息。如何将图标动

我有需要更改其值的tds。这样做时:

$(".class td:nth-child(2)").html("new value");
但我尝试在该值之前添加字体图标:

$(".class td:nth-child(2)").append("<i class=\"fa fa-arrow-up\"></i>");
$(“.td类:第n个子项(2)”)。追加(“”);
它将图标放在html之后。我希望它在html之前。看起来我需要追加,因为html清除了类信息。如何将图标动态放置在html之前?

使用
prepend()
将内容添加到父元素的开头:

$(".class td:nth-child(2)").prepend("<i class=\"fa fa-arrow-up\"></i>");
$(“.td类:第n个子项(2)”)。前缀(“”);

使用
prepend()
将内容添加到父元素的开头:

$(".class td:nth-child(2)").prepend("<i class=\"fa fa-arrow-up\"></i>");
$(“.td类:第n个子项(2)”)。前缀(“”);
您需要使用:

$(“.td类:第n个子项(2)”)。前缀(“”);
您需要使用:

$(“.td类:第n个子项(2)”)。前缀(“”);

您可以始终使用CSS3并将before/after分配给类,只需在jQuery中更改类即可

例如:

在您的情况下,类似于:

//The Css
.arrow-up:before {
  display: inline-block;
  height: 25px; 
  width: 25px;
  padding-right: 5px; 
  content: '<i class=\"fa fa-arrow-up\"></i>';
}

//The jQuery
$(".class td:nth-child(2)").addClass("arrow-up");
//Css
.向上箭头:之前{
显示:内联块;
高度:25px;
宽度:25px;
右侧填充:5px;
内容:'';
}
//jQuery
$(“.class td:nth child(2)”).addClass(“向上箭头”);

您可以始终使用CSS3并将before/after分配给类,只需在jQuery中更改类即可

例如:

在您的情况下,类似于:

//The Css
.arrow-up:before {
  display: inline-block;
  height: 25px; 
  width: 25px;
  padding-right: 5px; 
  content: '<i class=\"fa fa-arrow-up\"></i>';
}

//The jQuery
$(".class td:nth-child(2)").addClass("arrow-up");
//Css
.向上箭头:之前{
显示:内联块;
高度:25px;
宽度:25px;
右侧填充:5px;
内容:'';
}
//jQuery
$(“.class td:nth child(2)”).addClass(“向上箭头”);

然后使用
.prepend()
我刚刚为您更改了问题<代码>:)然后使用
.prepend()
我刚刚为您更改了问题<代码>:)谢谢,我想知道这样的方法是否存在。这正是我需要的。没问题,很高兴能帮上忙。谢谢,我想知道这样的方法是否存在。这正是我需要的。没问题,很乐意帮忙。