addclass

Adding class to clicked element

血红的双手。 提交于 2021-02-15 06:00:12
问题 I'm trying to add a class to a clicked element. There are multiple elements with unique IDs so I "don't know" what the ID of the element is. Can I use a modified version of the below code to achieve this? Jquery: $(document).ready(function () { $(this).on('click', function () { $(this).addClass('widget-selected'); }); }); EDIT: A markup can be like this: <h1 id="textHolder1" contenteditable="true">Text to edit</h1> 回答1: I would try with this.. $(document).ready(function () { //this will

Adding class to clicked element

心不动则不痛 提交于 2021-02-15 05:59:18
问题 I'm trying to add a class to a clicked element. There are multiple elements with unique IDs so I "don't know" what the ID of the element is. Can I use a modified version of the below code to achieve this? Jquery: $(document).ready(function () { $(this).on('click', function () { $(this).addClass('widget-selected'); }); }); EDIT: A markup can be like this: <h1 id="textHolder1" contenteditable="true">Text to edit</h1> 回答1: I would try with this.. $(document).ready(function () { //this will

Add/remove class on click to change background color of a div

半世苍凉 提交于 2021-01-27 19:27:25
问题 I've been trying to get a little black div to change color to green on click and change it back to black on the next click. I want it to keep doing this. Unfortunately it doesn't seem to work and through checking other topics on this I couldn't find my answer. My HTML: <div id="block"></div> My CSS: div { width: 100px; height: 100px; background-color: black; } My jQuery: $(function(){ $("#block").click(function(){ if($(this).hasClass("faded") == false) { $(this).css("background-color", "green

Add class to the last <li> in a group of <ul>

被刻印的时光 ゝ 提交于 2021-01-27 10:42:58
问题 I have a group of <ul> 's created dynamically and i need a class added to the last <li> of each one. I have: $('ul li:last').each(function(){ $(this).addClass("last"); }); But this only adds a class="last" to the last <ul> not in all of the <ul> 's. I want the last <li> of each <ul> to get added the class, not just the last <ul> . 回答1: :last, a propriety jQuery selector, pops off the last element from the set and returns it. :last-child, the CSS selector, selects the last child of each

Jquery If element has class which begins with x, then don't addClass

让人想犯罪 __ 提交于 2020-01-20 03:51:07
问题 I'm a definite newbie, so apologies for rubbish coding! I've written the following Jquery for a practice project I set myself: When you click on the div, it has the class "in_answerbox1" added and a cloned div is created in the answerbox with the class "answerbox_letter1" added. Eventually there will be many divs in a grid (or cells in a table) that when you click on a particular one, it will fade out and seem to appear in the answerbox. Then when you click on the thing in the answerbox,the

Sticky navbar makes content jump on way back up

荒凉一梦 提交于 2020-01-16 14:31:06
问题 I Have a simple site set up with a header, navbar and content. When the page reaches the navbar, the position becomes fixed so the navbar sits at the top of the page - at this point, the navbar height also gets a bit smaller (as I like this effect) - I have done this by adding separate classes, fixed and thinner to the navbar. Most people are aware of the issue that occurs when you add "position:fixed" to an inline element in that it makes the content suddenly "jump" upwards. To counteract

jQuery addclass doesn't work in twitter bootstrap carousel which using ng-repeat

核能气质少年 提交于 2020-01-16 02:05:08
问题 The issue I am facing now is jQuery addClass doesn't work under ng-repeat. The code below is from my partial page. I am trying to highlight the image when the user select it, unfortunately it doesn't get selected since I placed under ng-repeat div (first span3 div). On the other hand I can select the image with second span3 div - dynamic without ng-repeat (loading only one image only). Both uses the same jQuery script (posted below as well). Is there any alternative method to execute the task

Adding a “current” class to a clicked element and removing it when clicking on another element?

杀马特。学长 韩版系。学妹 提交于 2020-01-07 03:40:47
问题 I am trying to add a class of "current" to a div with jQuery and then remove the class when a different div is clicked. So far I have the "current" class being added, but I am not sure how to remove the "current" class from that div and apply it to the new div that is clicked. Here's the Javascript: $(document).ready(function() { $('#images div').click(function() { $(this).addClass('current'); $('.bios .active').hide().removeClass('active'); $('.bios div').eq($(this).index()).show().addClass(

Add class if input is empty and remove it if not

久未见 提交于 2020-01-06 19:59:06
问题 I would like to add a class if input is empty and remove it if it isn't. I initially had addClass(); so I tried using: .removeClass().addClass(); But it doesn't seem to update the class on the click of the button. HTML: <input id="firstName" type="text" /> <input id="lastName" type="text" /> <a href="#" id="button">SEND</a> jQuery: var firstName = $("#firstName"); var lastName = $("#lastName"); $('#button').click(function () { if(firstName.val() == "" || lastName.val() == ""){ firstName

how to wrap each letter to tag “span” and add the same id

删除回忆录丶 提交于 2020-01-05 08:14:19
问题 This is what i have now: DEMO Need for each letter add ID same as letter in span... like this: <span id="t">t</span> <span id="e">e</span> <span id="s">s</span> <span id="t">t</span> Thanks HTML: <div id="page-wrap"> <div class="form_floleft"> <form> <label for="">Your word:</label> <input class="text_field" type="text" name="your_word" placeholder="enter here"> </form> <div class="enter">ENTER</div> </div> <div class="txt"></div> <p></p> </div> JS: (function($){ jQuery(document).ready