Jump to content

Move an input with Jquery after setting as a variable


Adamhumbug
Go to solution Solved by requinix,

Recommended Posts

Hi,

I am trying to move an element with JQ.

I am wanting to add the input box to some appended content to a page.

My code is below:

		$("[id^='OPRow']").each(function(index, value){
			var fn = $("[id^='op_firstname']", this)
			console.log(fn)
			var ln = $("[id^='op_lastname']", this)
			var nation = $("[id^='op_nationality']", this)
			var mobile = $("input [id^='op_t1']", this)
			var cc = $("select [id^='op_t1d']", this)
			var role = $("[id^='op_role']", this)
			var e1 = $("select [id^='op_e1']", this)
			var cc = $("select [id^='op_t1d']", this)

			$('.content').append("<div class='row'><div class='col-6'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'>"+fn+"</div></div><div class='col-6'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div><div class='row'><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div><div class='row'><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div>")


		})

The output i am getting is [object Object] where the element should be placed.

I would appreciate any help with this trying to put the input into the content that gets append to $('.content')

Link to comment
Share on other sites

  • Solution

You can't mix HTML strings and HTML elements together like that.

Construct the HTML as a string if you wish, if that's easier to do, but you'll have to .append fn and whatever into it separately. For example,

var row = $("<div class='row'>...</div>");
row.find("label[for='basic-url'] + div").append(fn);

$(".content").append(row);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.