select elements that don't contain a specific image with jquery - javascript

Hi I am trying to use jQuery to select all elements which have the class of "icon" which do not contain a particular image (to turn them off for filtering content)
I could do something like the example below, but it would seem like there would be a much cleaner way to select all elements that don't contain that image src to hide them.
Thank you for your feedback!
$('.icon').hide();
$('.icon').find('img[src$="'+src+'"]').parent().parent().show();

$('.icon').find('img[src !="'+src+'"]').hide(); may work

Related

How to select element has id start and end with specific text using jquery?

I have multiple divs with ids like course1_popup, course2_popup, course3_popup. I want to make a function something like
$('#course*_popup').hide();
so that all course*_popup divs should hide but this is not working. Any Ideas?
Use the combination of attribute starts with and ends with selectors.
$('[id^="course"][id$="_popup"]').hide();
FYI : It would be much better to use a common class for the group of elements for such things.
Easiest way: Give all the same class like course_popup and then:
$('.course_popup').hide()
Other solution was postet a sec ago ;)

Is there a way of selecting elements by their title in JS?

I am trying to create a program to select elements on the page, but it seems that the only thing that makes them unique are there titles. Is there any way of selecting certain things on a web page by their titles? I found this script but it will not select or click on the elements.
What am I doing wrong? Any help will do. Thanks
How can I get it to work on A and not div, sorry, that was the problem
My script that I am using --
$(document).ready(function () {
$("a[title=\"Learn More About Becoming A VIP\"]").click();
});
It says Div is not defined when I try to run script. Why So?
There is a way to select elements by their title attribute in javascript:
document.querySelectorAll('div[title="john"]');
======
You can also select elements that have a title beginning with john:
document.querySelectorAll('div[title^="john"]');
Or elements that have the (space-bounded) word john somewhere in their title:
document.querySelectorAll('div[title~="john"]');
Your selector should work if title value is john. You might wan't to select element that contains certain string as follow:
$('div[title*="john"]')

Change text in dynamically created textbox

I have a bunch of textboxes that are created dynamically one per click.
They all have the same name "discount[]", same id "discount" and have the same class "tinput".
Is there anyway that I can use to change the text in all of these textboxes with javascript or jquery?
I have another bunch of the dynamically created text boxes.
The id and name are unique but the class remains the same.
If it gets the job done, I can change the class name.
Anyhelp is greatly appreciated.
Regards,
You definitely shouldn't use an id more than once per document. If you need it for a <label> you might want to consider putting the input in the <label>.
You are using the class attribute the right way, though. You can do:
$('.tinput').val('New value for all .tinputs!');
If you can't put the input inside the label you can use use this. I made this demo for someone a little while ago. It might be helpful. It'll increment an id like "id-1".
http://jsbin.com/APegOMo/3/edit?html,js,output
same id "discount"
Please, don't do that! "id" is to identify a dom element. That hurts in my soul.
If every id is unique you could access them by $("#myid").val("my new val"). Just an example.
Regards, - Tobbo
here is a simple example that takes all elements with a particular class name and changes the .html, not 100% sure I understand what you're after though. if you need to do someting specific with each divs text you can iterate through them by id (and maybe class as well) and change each divs individual .html.
if you can share a stripped down example of your code or elaborate I'd love to try to help. good luck.
$(".changeDivs").html("adfasdf");
jsfiddle example >>

Disable all Radcomboboxes inside a div

I have several telerik radcomboboxes inside a div with various id's. I want to find all of them and disable them without using those id's like say finding the tag name using javascript.
Please help
Each RadControl renders a specific CSS class identifying the type of the control on the control container element. Additionally the JS object is an expando of the container element - control.
So, you can use this: $('.common-container-class-name .RadComboBox').each(function() { this.control.disable(); });
Not sure what a Rad Combo Box is but it seems like different types of input / text elements so try:
$('.someContainerDiv input').attr('disabled','disabled');
Change input for whatever the element is, like the <textarea> tag.

JQuery remove images

I'm curious if anyone knows why this piece of jQuery code doesn't remove the images?
var a = $('#tblMain').clone().remove('img');
The table is being selected. This is trying to take the table on the webpage and export to excel but I do not want the images to export.
Thank you,
Do it like this:
$("#tblMain").clone().find("img").remove();
EDIT: Okay, here's the problem:
selector: A selector expression that
filters the set of matched elements to
be removed.
http://api.jquery.com/remove/
The img in .remove('img') is to filter the set of items in the jquery object, NOT to find elements within the items themselves. In this case, the jquery object contains only one item, the cloned table. Therefore, .remove('img') removes nothing, since the jquery object does not contain any images (only images within items it contains).
I don't know what's happening behind the scenes, but you're referring to some variable called img whilst you most probably just want to select all img elements. In that case, you ought to use a selector as a string:
var a = $('#tblMain').clone().remove('img');
EDIT: .clone.remove does not seem to work indeed. I used this workaround which actually works:
.find('img').each(function() {$(this).remove()});

Categories

Resources