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);
Related
This question already has answers here:
jQuery: Check if div with certain class name exists
(19 answers)
Closed 7 days ago.
I have some code that creates a new paragraph element within a div and gives it the class "taskparagraph". I want to check if any elements with this class exist, and if not, add another (unrelated) paragraph.
I genuinely have no clue how to do something like this even though it seems like such a simple task. Maybe I'm just not Googling the right things...
P.S. I do not plan on using any JS libraries like jQuery for now. If using something like that is the only possible way to do this task please let me know.
You can use document.querySelector:
if (!document.querySelector('.taskparagraph')) { // or compare with null
// no element with class "taskparagraph" exists
}
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 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");
This question already has answers here:
jQuery OR Selector?
(6 answers)
Closed 9 years ago.
I am working on an ASP.NET page in which I generate some JavaScript code based on values in a database.
For example, in the database there might be the formula sum([#itemA]), which would evaluate to something like $('#itemA').change(function(){ sum(this); });.
I know that I can select elements using jQuery selectors such as $('[id*=itemA]') or $('[class*=itemA]'), but I am wondering if there is any way to combine these selectors so that any element with either a class or an ID of itemA would be selected.
Right now in my code I am just using if/else blocks to deal with ID's or classes, but if there is an easier implementation, I would love to use it.
I looked at the jQuery documentation and googled around a bit, but I didn't see anything that answered my question.
Thanks in advance!
This should do the trick
$('[id*=itemA], [class*=itemA]')
For more details, take a look to official jquery documentation
Use multiple selectors like
$('.class1, .class2....., .classn')
You can literally use anything like ID names, class names or selectors like you specified separated by commas
Like in css, when selectors are separated by ,they are cumulated :
var elements = $('[id*=itemA], [class*=itemA]')
This question already has answers here:
jQuery selector to get form by name
(4 answers)
Closed 8 years ago.
I have multiple forms on a page. How do I find a form by its name? I think in pure javascript it is something like document.forms['FormName'] .
I want to do a form.submit. But I want to be able to select a form by its name.
You can add an attribute selector to get the form you want:
$('form[name="foo"]')...
No jQuery required -- just use the built-in JavaScript submit() method:
document.forms['FormName'].submit();
Give your form an ID or class attribute. In the case of an ID:
$("#formName").function()
Your HTML:
<form id="formName">
Where function is what you plan on doing...