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
48
votes
2 answers

jQuery check if attr = value

I seem to be having trouble with my code. I need to say: if ( $('html').attr('lang').val() == 'fr-FR' ) { // do this } else { // do that } When I check the console, I just get an error telling me this isn't a function. Help would be…
beefchimi
  • 1,222
  • 2
  • 15
  • 34
44
votes
9 answers

Jquery - animate height toggle

I have a 10px bar along the top of the screen that, when clicked, I want it to animate to a height of 40px and then if clicked again, animate back down to 10px. I tried changing the id of the div, but it isn't working. How could I get this to work,…
We're All Scholars
  • 561
  • 2
  • 5
  • 7
42
votes
4 answers

How does one add an attribute to a model?

In rails I generate a model with two strings and would like to add more. How would I go about doing this?
jsttn
  • 1,435
  • 3
  • 16
  • 21
42
votes
4 answers

Conditionally make input field readonly in Angular 2 or 4: Advice + Best/which way to do it

I was attempting to answer someone elses question. And in doing so realised there was quite a bit of uncertainty in my mind about a few things. I'm hoping someone can provide feedback on the numbered points 1..4: Task: Conditionally make input field…
JGFMK
  • 7,107
  • 4
  • 46
  • 80
38
votes
4 answers

Use declare styleable to set custom component input type

I have a CompositeComponent (EditText+ImageButton) When clicking on button the edittext content will be cleared. It is working fine. My problem is setting attributes to my component. I am using declare-styleable to set attributes to my component. I…
Mahendran
  • 2,621
  • 5
  • 25
  • 47
36
votes
2 answers

Get value of custom attribute

I have two radio buttons. I would like to be able to get the value of the custom attribute "xmlvalue" of the checked radio button. I have tried with the following script: var userType = $("input[name=ctrl_CustomerType]:checked",…
Meek
  • 2,526
  • 7
  • 29
  • 52
35
votes
4 answers

jQuery attr('onclick')

I'am trying to change "onclick" attribute in jQuery but it doesn't change, here is my code: $('#stop').click(function() { $('next').attr('onclick','stopMoving()'); } I have an element with id="stop" and when user clicks on it I want to change…
Shark
  • 1,093
  • 4
  • 11
  • 20
31
votes
7 answers

How do I set an attr_accessor for a dynamic instance variable?

I dynamically created an instance variable within my class: class Mine attr_accessor :some_var def intialize @some_var = true end def my_number num self.instance_variable_set "@my_#{num}", num end end How do I make @my_#{num}…
eywu
  • 2,454
  • 1
  • 20
  • 24
30
votes
6 answers

jQuery get the name of a select option

I have a dropdown list with several option, each option has a name attribute. When I select an option, a different list of checkboxes needs to appear - when another options is selected, that checkbox list should disappear and another one be…
Sam Skirrow
  • 3,297
  • 15
  • 46
  • 91
28
votes
1 answer

Should href be set with prop() or attr()?

If I want to change the href of a link dynamically, should I do so using prop() or attr()?
Francisc
  • 66,160
  • 57
  • 172
  • 264
28
votes
4 answers

Why jQuery 1.9+ attr() method not deprecated?

Can I, a jQuery1.9+ software developer, "deprecate" the use of the attr() method in my day-by-day work? As showed in many questions, .prop() vs .attr() (main) jQuery attr vs. prop, there are a list of props? jQuery attr vs prop? Migrating jQuery…
Peter Krauss
  • 11,340
  • 17
  • 129
  • 247
25
votes
4 answers

Does the attr() in jQuery force lowercase?

I'm trying to manipulate the svg 'viewBox' attribute which looks something like this: ... Using $("svg").attr("viewBox","..."); However, this creates a new attribute in the element called…
bzuillsmith
  • 3,072
  • 3
  • 20
  • 38
22
votes
5 answers

JQuery - File attributes

Trying to access file attributes from an input field after a file is selected. Tried this but get the error 'file not defined' var file = $("#uploadedfile").prop("files")[0]; var fileName = file.fileName; var fileSize =…
JimmyJammed
  • 9,308
  • 17
  • 74
  • 140
21
votes
1 answer

Using attribute to modify a drawable element color

I try to make a custom Drawable by using attribute but I have an inflating error 01-21 11:01:06.171: E/AndroidRuntime(13695): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/action_bar_background.xml from drawable…
Ahmet
  • 261
  • 2
  • 8
21
votes
2 answers

How to add documentation to custom attributes?

I know how to create custom attributes for views, for example:
cottonBallPaws
  • 20,217
  • 37
  • 119
  • 169
1
2
3
79 80