Jquery not disabled the parent [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Input tag not disabled.This is my code.Please help me.
var input = $('input[value="' + $(this).val() + '"]');
input.prop('disabled', true);
input.parent('li').addClass('disabled');

You should use filter() to find the input with value instead of using Attribute value selector.
Reduce the set of matched elements to those that match the selector or pass the function's test.
Also you can use closest() to traverse up to desired parent.
Script
var value = $(this).val();
var input = $('input').filter(function(){
return value == $(this).val();
}).prop('disabled', true);
input.closest('li').addClass('disabled');

Related

How to make the following JavaScript code work and result in a list of names and ages inside the element with ID "myDivId" : [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to make the following JavaScript code work and result in a list
of names and ages inside the element with ID "myDivId" :
<div id="myDivId">No results yet</div>
<script>
new PersonPrinter("myDivId",[{"name":"Joe","age":"23"}
{"name":"Sam","age":"31"}]).render();
</script>`
In the PersonPrinter render function you need to update the div
PersonPrinter.prototype.render = function(id,data) {
var elem = document.elementById(id);
for (var i =0;i <data.length;i++) {
var d = dcoument.createElement('div');
d.appendChild(document.createTextNode('Name'+data.name +' Age:'+data.age');
elem.appendChild(d);`enter code here`
}
}
You need to access div id using innerHTML
var a = Document.getElementById('myDinId');
And for changing value use simply = operator
a.innerHTML = 'Something';

how to insert variable into jquery selector [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to insert a variable inside a jQuery selector like this example, how can I fix my problem?
var index = 5;
$(".tables li:nth-child('+index+')").addClass('vr_active');
The issue is in the quotes ...
var index = 5;
$(".tables li:nth-child("+index+")").addClass('vr_active');
This way, the index variable is part of a concatenation of:
".tables li:nth-child(" ... a string
index ... a variable
")" ... a string.
Functioning jsFiddle
try to use .eq()
var index = 5;
$(".tables > li").eq(index - 1).addClass('vr_active');
A jQuery selector is just a string.
So your problem is actually "How to insert a variable into a string" and this can be done in a myriad of ways, for example:
".tables li:nth-child(" + index + ")"
var selector = ".tables li:nth-child(${index})";
selector = selector.replace("${index}", index);
etc.

How to use jquery selectors on list of elements? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
var checkboxes = $('.checkboxes');
doSomething(checkboxes);
var checked = // get checked checkboxes from checkboxes
// not efficient since we already have all checkboxes
$('.checkboxes:checked');
// not correct,
$(':checked', checkboxes);
// not efficient and can be incorrect
$(':checked', checkboxes.parent());
How do I use selectors on the checkboxes themselves?
You can get the checked checkboxes with a filter :
var checkboxes = $('.checkboxes');
doSomething(checkboxes);
var checked = checkboxes.filter(':checked');
Try checkboxes.find(':checked');

jQuery filter options with value greater (less) than variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need to disable values of options in select that are less than some number, which I do not know beforehand (it is set in another form element). I need something like code below, but with variable value of "variableInteger":
select.children().filter(function() {
return $(this).attr("value") > variableInteger;
}).each(function () {$(this).attr('disabled', 'disabled')});
Is there some clever way to do it?
PS. variableInteger value is from another form element, which name is also known only at runtime.
No need for the .each, also make use of prop and this.value (no need for $(this).attr("value");)
select.children("option").filter(function() {
return this.value > variableInteger;
}).prop("disabled", true);

How to find a certain class using .find() or some jQuery Syntax? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
if( hasWhiteSpace($(this).find(".nospace:input").val()) ){
$(this).find(".nospace:input").filter(function() {
return hasWhiteSpace(this.value) == true;
}).addClass("blank");
setError(".motd_register_company","There must be no space in between.");
return false;
}
There is something wrong about my code above, and the code only validate the first input, while the others not, how could I validate all the "nospace" class that I have in my form?
can you guys trim my code if there is something wrong.
Are you trying to recursively search elements for a particular classname? If so:
$('input.class_name').each(function() {
// Do you stuff to this input element
});
jQuery.each("input.nospace", function(i, el){
var self = $(el);
if(hasWhiteSpace(self.val()) self.addClass("blank");
});

Categories

Resources