jquery - Testing to see if a text string is part of a variable -


i'm setting variable contents of h1 tag on site. want write if statement tests see if there specific word inside h1 tag. need set dropdown based on title of form.

so, have html.

<div id="booking-details"><h1>this los angeles</h1></div> 

here jquery:

var city = $('#booking-details h1').text(); if (city.text().indexof('los angeles') >= 0)) {alert("this city los angeles")}; 

i'm getting syntax error , not quite sure how pull index of text variable.

thanks in advance help.

you using text() twice, do:

var city = $('#booking-details h1').text(); if (city.indexof('los angeles') >= 0)) {alert("this city los angeles")}; 

or:

var city = $('#booking-details h1'); if (city.text().indexof('los angeles') >= 0)) {alert("this city los angeles")}; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -