This question already has answers here:
How can I select an element with multiple classes in jQuery?
(14 answers)
Closed 6 years ago.
I am using jquery bootpag to display pagination on a page
<div class="textgray showing"></div>
How should I tell jQuery to select this div? I tried the following without but neither of these attempts work
$(".textgray .showing").html("some text");
$(".textgray showing").html("some text");
P.S I am a beginner in frontend so bear with me
The space means the second part is inside the first one (it's called the descendant combinator). Remove it:
$(".textgray.showing").html("some text");
You don't need to put that extra space in between selector. space in selector looks for descendant elements:
$(".textgray.showing").html("some text");
Related
This question already has answers here:
Create <div> and append <div> dynamically
(9 answers)
Closed 2 years ago.
I used a query selector to get the div i want to append. But the created div doesn't want to append to anything other than the body. Is there a way i can make it specifically append under the div?
Look at this: https://www.w3schools.com/jsref/met_node_appendchild.asp
What you need to do is
parent.appendChild(thatDiv);
This question already has answers here:
Selecting multiple classes with jQuery
(4 answers)
Closed 3 years ago.
I'm a beginner and I'm wondering if there is a way to remove multiple attributes once without coding for each one.
For an example, please look at my code sample below.
$(".select-us").attr("disabled",true);
$(".select-as").attr("disabled",true);
$(".select-eu").attr("disabled",true);
$(".select-oc").attr("disabled",true);
I just want to know if there is any simpler way to do this. Thanks for your time.
$(".select-us, .select-as, .select-eu, .select-oc").attr("disabled", true);
Please wrap your multiple form elements in fieldset and disable/ enable this only
<fieldset id='fset' disabled={true}>
...
can disable and enable with jquery like this
$("#fset").attr('disabled', true)
Add a new class to every element like "select-all" and do:
$(".select-all").attr("disabled",true);
This question already has answers here:
How can I find elements by text content with jQuery?
(8 answers)
Closed 4 years ago.
how can I remove an element using jquery by the text in the element.
Link1
I dont want to remove the element by class or ID. I want to do something like this:
$('a').html('Link1').remove()
Can you help me with this?
Please try this
jQuery
$('a:contains("Link1")').remove();
Demo fiddle
For more reference please refer this.
This question already has answers here:
How to change a text with jQuery
(8 answers)
Closed 6 years ago.
I have a javascript code. The code always appends some text to an old one. But I dont want that the text is attached to the old text. Instead, I want that it replaces the old text.
Here is the code line:
$("#werkstatt").append("Text");
How can I do that?
Thank you very much!
You have to use empty() method.
$("#werkstatt").empty().append("Text");
or simply you should use .text() method.
$("#werkstatt").text("Text");
This question already has answers here:
How to append one jQuery element already in the DOM to another element?
(5 answers)
Closed 3 months ago.
I am writing a Greasemonkey userscript, with jQuery. The segment of code affects forum thread pages, and intends to append a button to the footer of every post.
Assume the button is already a jQuery element $button, this is the code I have:
$('table.posts').each(function() {
//get the name of the poster
profileName = $(this).find('.user').text();
//change the link relative to each poster
$button.attr('href', '/search?user=' + profileName);
//This is the problematic line:
$(this).find('div.postFooter').append($button);
});
I have tested the value of profileName using an alert, and it successfully iterates through and alerts the profile names, but it only appends the button to the last post's footer (with the correct link).
I've tried using a variety of different selectors and ways to traverse the DOM to the required element, but all methods have resulted in the same thing. I'm out of ideas.
Use clone:
$(this).find('div.postFooter').append($button.clone(true));
Everytime you are changing and appending the same $button element.