Alejandro Silva Alejandro Silva - 5 months ago 8
jQuery Question

I want to add the placeholder attribute to the input within this DIV but it does not have a unique property that I could locate it with

I cannot edit the HTML directly because Squarespace does not allow that, only JS and Jquery can be used.

$("#field city :input").attr('placeholder', 'City');


I tried using this but it doesn't work

<div class="field city">
<label class="caption"><input class="field-element field-control" name="" x-autocompletetype="" type="text" spellcheck="false" data title="">
</label>
</div>


Thanks in advance

Answer

Your selector is not correct for the html provided.

This works:

$(".field.city .field-element").attr('placeholder', 'City')

Fiddle

Comments