Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery if div contains text, toggle button

I'm trying to get a button to be toggled if a div contains a string of text. Something like:

$(document).ready(function(){
$(function() {
if ('$div#trackingnumber:contains('Hello')');') {
    $("dinput#submitam").toggle()});
}
});

Does anybody know how to do this?

like image 739
henryaaron Avatar asked Jun 09 '26 05:06

henryaaron


1 Answers

You are on the right way. I only see some syntax errors. Try this

$(document).ready(function(){
     if ($("#trackingnumber:contains('Hello')").length != 0) 
     {
         $("dinput#submitam").toggle();
     }
});

Checkout this jsFiddle too.

like image 110
dknaack Avatar answered Jun 10 '26 18:06

dknaack