Skip to content Skip to sidebar Skip to footer

Use Function Data As Html Id Jquery

I want to use the function data as id, tried alot but nothing worked, how should i do it here is my code, thanks in advance function SLIDE_HIDE(SLIDEID) { $('#($SLIDEID).val()

Solution 1:

You need to concatenate:

$("#" + SLIDEID)

Which means that if the SLIDEID argument is, say, the string "test" then it will be like saying $("#test").

You were trying to select an element with an id equal to all of the text in the string after #, i.e., an element with id="($SLIDEID).val()".

If you are trying to hide the element that has the id in the SLIDEID argument then do this:

$("#" + SLIDEID).hide();

If you want to change that element's value then (assuming it is a form element like an input):

$("#" + SLIDEID).val('hide');

The code you showed sort of looks like you're trying to retrieve the value from an element with the id specified in SLIDEID and then use that value as the id to look up another element and set that other element's value to the string 'hide'. That doesn't really make sense to me, but if it's what you want to do:

$("#" + $("#" + SLIDEID).val()).prop('value', 'hide');

Post a Comment for "Use Function Data As Html Id Jquery"