0
I have the following code:
var valuePlan = variavel > 0 ? $('<a>').attr({
target: '_blank',
href: 'file.php'
}).append( m.plan ) : ''
In the code above, I check if the variable is greater than zero, then mount a link, otherwise it is empty
If it’s bigger than zero, I’d like to know how to show in html as url
I tried to do it like this
html( valuePlan )
But it makes the following mistake:
Uncaught ReferenceError: html
I would like the above object to become a normal link within a td that was added via javascript:
Example:
<table>
<thead>
<th>Titulo</th>
</thead>
<tbody class="tbody">
</tbody>
</table>
<script>
var variavel = 1
var valuePlan = variavel > 0 ? $('<a>').attr({
target: '_blank',
href: 'file.php'
}).append( m.plan ) : ''
var cell = "<td>"+valuePlan+"</td>"
$('.tbody).find('tr').remove()
$('.tbody').append( cell )
</script>
I actually want to add to a table cell via javascript. Ex "<TD>"+valueplan+"</TD>"
– adventistaam
So the method remains the same (
.append
), what you have to do is change the jQuery selector, in the example I put the"body"
, how do you want to use in aTD
you will have to make the selector so that comes to thisTD
, or prepare her for it Ex. add the class"vai-receber-ahref"
inTD
and the jQuery selector would look like this:$("TD.vai-receber-ahre")
now just use theappend
same as the example– Icaro Martins
I edited the question, sorry I wasn’t clear
– adventistaam
So it’s only possible through one element of the gift, right?
– adventistaam
I didn’t understand this last question right. -- To add to the page you need to add to an element already on the page. Now create you could create ate as string Ex.
$("TD").append( "<a href='index.php'>Meu Link</a>" )
, Obs. in this case could use up to the.html( str )
instead of.append( str )
– Icaro Martins