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.

1197 questions
2384
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 aka Neal
  • 138,754
  • 36
  • 231
  • 295
216
votes
5 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
  • 97,234
  • 40
  • 163
  • 203
197
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,061
  • 8
  • 29
  • 40
142
votes
17 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? Thank you in advance. It shows that some…
Dipti Belurgikar
  • 1,531
  • 2
  • 5
  • 5
120
votes
5 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,055
  • 5
  • 37
  • 54
108
votes
6 answers

How to find elements with 'value=x'?

I need to remove element that have value="123". I know that all elements with different values are located into #attached_docs, but I don't know how to select element with value="123". $('#attached_docs').find ... .remove(); Can you help me?
daGrevis
  • 19,600
  • 35
  • 95
  • 134
103
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
  • 79,753
  • 103
  • 257
  • 412
78
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 …
PSR
  • 36,137
  • 33
  • 104
  • 147
69
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
  • 6,794
  • 10
  • 50
  • 81
59
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,372
  • 3
  • 17
  • 27
53
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,311
  • 19
  • 75
  • 144
53
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,276
  • 4
  • 18
  • 38
52
votes
9 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
  • 10,952
  • 17
  • 63
  • 120
51
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,357
  • 8
  • 34
  • 52
1
2 3
79 80