简体   繁体   English

如何执行第二个jQuery代码段来添加HTML代码

[英]How to execute second jQuery snippet to add html code

I'd like to remove all class that have icons on them. 我想删除所有有图标的课程。 Also, I'd like to replace their HTML code. 另外,我想替换他们的HTML代码。

There is .icon-eye-open that got font awesome icon on it, i want to change it for twitter heart snippet. .icon-eye-open ,上面有字体真棒图标,我想改为twitter心形片。

I managed to remove class, so i have empty space to add html code but i stuck in choosing the way how to. 我设法删除了类,所以我有空的空间来添加HTML代码,但我坚持选择如何的方式。 I googled a lot of diffrent ways, but the jQuery looks the easiest to fire off, but apparently its not working. 我用Google搜索了很多不同的方法,但jQuery看起来最容易点火,但显然它不起作用。

$(document).ready(function() {
$('.visible-desktop').after('<a href="/basketedit.php?mode=2"><input id="toggle-heart" type="checkbox"/><label for="toggle-heart">❤</label></a>');
});

The point is that i can't touch HTML or parcial css. 关键是我无法触及HTML或parcial css。 Codepen: https://codepen.io/graphconcept/pen/vwNNwQ Codepen: https ://codepen.io/graphconcept/pen/vwNNwQ

If your code is the same as what's in your script, JS does not go well with litteral linebreaks in strings; 如果您的代码与脚本中的代码相同,那么JS在字符串中的字符串换行方式上并不顺利;

You'll have to escape the linebreak 你将不得不逃避线路

$(document).ready(function() {
    $('.visible-desktop').after('<a href="/basketedit.php?mode=2"><input id="toggle-heart" type="checkbox"/> \
    <label for="toggle-heart">❤</label></a>');
});

-OR- Concatenate the 2 strings - 或 - 连接2个字符串

$(document).ready(function() {
    $('.visible-desktop').after('<a href="/basketedit.php?mode=2"><input id="toggle-heart" type="checkbox"/>' +
    '<label for="toggle-heart">❤</label></a>');
});

-OR- Like Roy said in the comments, remove the break. - 或 - 像罗伊在评论中所说,删除休息。

$(document).ready(function() {
    $('.visible-desktop').after('<a href="/basketedit.php?mode=2"><input id="toggle-heart" type="checkbox"/> <label for="toggle-heart">❤</label></a>');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM