0

Having some problems, trying to insert a string into the placeholder element on an HTML form. Declared a variable to use for parameter in each function, not sure if this is the correct way ...

var placeholder_value = $(search-typing).prop('placeholder');

Little experience with jQuery, can someone please assist

http://jsbin.com/araget/306/

Kyle
  • 1,153
  • 5
  • 28
  • 56

2 Answers2

0

Not sure if it's a typo, but search-typing isn't a variable name: variables can't have a dash/minus in them. You'd need a variable like search_typing.

There's a great post What characters are valid for JavaScript variable names? on this.

Community
  • 1
  • 1
  • 'search-typing' is the ID attribute on the form that I'm trying to get value of – Kyle Nov 13 '13 at 03:01
  • This is what you need then: http://learn.jquery.com/using-jquery-core/selecting-elements/ – rgin Nov 13 '13 at 03:04
  • Yep, rgin is right, b/c then you'll have $('#search-typing') instead. –  Nov 13 '13 at 03:38
0
var placeholder_value = $('#search-typing').prop('placeholder'); 

You need to use a proper prefix on your selector, Use a # to get an element by its id. Use a period to get an element (or elements) by class - i.e:

$('.myClass').prop('placeholder'); 

You also need to enclose it in quotes as above.

This is pretty good interactive way to learn the basics behind jQuery

https://www.codeschool.com/courses/try-jquery

Carl Wilson
  • 189
  • 1
  • 11