jQuery need refresh to get the html()
I automatically generate input tag on each link within the form make the
.html() from the link become input val(). The text that I want to get is
inside a < strong > tag this is why I use .children() function.
The problem is that this code need a page refresh to work properly.
However var htmltoval return 'undefined' I try to put this loop before,
after, on $(document).ready etc...
I guess it's because the elements was dynamically added.
Here is the code:
var content_input = '<input class="btn_menu_search" type="radio"/>';
$('form#form_search a').after(content_input);
$('#form_search :input').each(function () {
var htmltoval = $(this).prev('a').children().html().toLowerCase();
console.log(htmltoval) // return undefined on first page load
// however return the inner html string as expected
var htmltoval = htmltoval.split(' ').join('');
$(this).val(htmltoval);
});
Any ideas?
No comments:
Post a Comment