Questions tagged [attr]

This tag should be used for attribute related issues.

An attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such.

1255 questions
2485
votes
18 answers

.prop() vs .attr()

So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style'); }) or in this case do they do the same…
Naftali
  • 144,921
  • 39
  • 244
  • 303
256
votes
7 answers

Set attribute without value

How do I set a data attribute without adding a value in jQuery? I want this: I tried: $('body').attr('data-body'); // this is a getter, not working $('body').attr('data-body', null); // not adding anything Everything else seems to…
David Hellsing
  • 106,495
  • 44
  • 176
  • 212
220
votes
6 answers

Toggle input disabled attribute using jQuery

Here is my code: $("#product1 :checkbox").click(function(){ $(this) .closest('tr') // Find the parent row. .find(":input[type='text']") // Find text elements in that row. …
Tommy Arnold
  • 3,339
  • 8
  • 31
  • 40
160
votes
20 answers

Error:(9, 5) error: resource android:attr/dialogCornerRadius not found

So I installed android studio 3.0.1 and as soon as it opened the gradle built and showed the following errors. I tried adding dependencies such as design and support but in vain. Could someone help me? It shows that some attributes such as…
Dipti Belurgikar
  • 1,711
  • 2
  • 7
  • 5
131
votes
6 answers

How to get an enum which is created in attrs.xml in code

I created a custom View (find it here) with an declare-styleable attribute of type enum. In xml I can now choose one of the enum entries for my custom attribute. Now I want to create an method to set this value programmatically, but I can not access…
Informatic0re
  • 6,300
  • 5
  • 41
  • 56
121
votes
6 answers

jQuery find elements with value = x

I need to remove element that have value="123". I know that all elements with different values are located in #attached_docs, but I don't know how to select element with value="123". $('#attached_docs').find ... .remove(); Can you help me?
daGrevis
  • 21,014
  • 37
  • 100
  • 139
104
votes
4 answers

jQuery attr vs prop?

Now this isn't just another What's the difference question, I have done some tests(http://jsfiddle.net/ZC3Lf/) modifying the prop and attr of
​ with the output being: 1) prop Modification test Prop:…
Hailwood
  • 89,623
  • 107
  • 270
  • 423
84
votes
3 answers

difference between prop() and attr() in jQuery and when to use attr() and prop()

I saw in some places .attr() is used in jQuery.In some places .prop() is used.But i searched in SO and google i am very confused .Please tell me the exact difference between these two and when to use them. I have seen the following links jQuery attr…
PSR
  • 39,804
  • 41
  • 111
  • 151
77
votes
2 answers

How can I replace a window's URL hash with another response?

I am trying to change a hashed URL (document.location.hash) with the replace method, but it doesn't work. $(function(){ var anchor = document.location.hash; //this returns me a string value like '#categories' $('span').click(function(){ …
Barlas Apaydin
  • 7,233
  • 11
  • 55
  • 86
76
votes
4 answers

CSS set background-image by data-image attr

I have sort of elements with this pattern:
I want to set this elements background-image to data-image. I test this CSS code: div[data-image] { border: 2px solid black; background-image:…
Hossain Khademian
  • 1,616
  • 3
  • 19
  • 29
67
votes
2 answers

Setting new value for an attribute using jQuery

I am trying to set a new vale of a custom attribute of a div using attr(). I found out it can be done using .attr( attributeName, value ), but when I try it it's not working. Here is the part of my code I am interested in: $('#amount').attr(…
Sakshi Sharma
  • 1,414
  • 4
  • 20
  • 39
64
votes
2 answers

jquery: get value of custom attribute

html5 supports the placeholder attribute on input[type=text] elements, but I need to handle non-compliant browsers. I know there are a thousand plugins out there for placeholder but I'd like to create the 1001st. I am able to get a handle on the…
bflemi3
  • 6,698
  • 20
  • 88
  • 155
57
votes
10 answers

jQuery .attr("disabled", "disabled") not working in Chrome

Not sure why this isn't working. When people click the 'edit' button of my application, the disabled textfields become editable: $("#bewerken").click(function(e) { $("input[disabled='disabled']").removeAttr('disabled'); }); I then want to…
Joris Ooms
  • 11,880
  • 17
  • 67
  • 124
52
votes
4 answers

How do I add selectableItemBackground to an ImageButton programmatically?

android.R.attr.selectableItemBackground exists, but how do I add it programatically to an ImageButton? Also, how would I go about finding the answer in the documentation? It's mentioned here, but I don't see any explanation of how it's actually…
abc32112
  • 2,457
  • 9
  • 37
  • 53
1
2 3
83 84